View Full Version : سوال: ـغییر اندازه نسبی خطوط!
Saman_12
جمعه 21 بهمن 1390, 22:33 عصر
سلام دوستان.
به این کد توجه کنید :
<Canvas>
<Canvas.Resources>
<PathGeometry x:Key="LineData">
<PathFigure StartPoint="100,100">
<PathFigure.Segments>
<PolyLineSegment Points="250,100 250,150 100,150 100,200 400,200 400,100 550,100 550,250 100,250 100,400 250,400 250,300 550,300 550,350 400,350,400,400 550,400"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</Canvas.Resources>
<Rectangle
Width="30" Height="30" Fill="Blue">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform" />
</Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Path.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever" AutoReverse="True">
<DoubleAnimationUsingPath
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="X"
PathGeometry="{StaticResource LineData}"
Source="X"
Duration="0:0:5" />
<DoubleAnimationUsingPath
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="Y"
PathGeometry="{StaticResource LineData}"
Source="Y"
Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</Canvas>
میخوام تو این کد وقتی سایز پنجره رو تغییر میدم اندازه خطوط به طور نسبی (به نسبت پنجره) تغییر کنه!
با تشکر از دوستان.
Saman_12
یک شنبه 23 بهمن 1390, 19:11 عصر
رو منطق برنامه هم پیادش کردم اما بازم جواب نداد :
Private Movex, Movey As New DoubleAnimationUsingPath
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim trxy As New TranslateTransform
Dim Pathg As New PathGeometry
Dim pathf As New PathFigure
Dim pline As New PolyLineSegment
Dim st As New Storyboard
Me.RegisterName("trxy", trxy)
Movex.AutoReverse = True
Movex.RepeatBehavior = RepeatBehavior.Forever
Movex.Duration = TimeSpan.FromSeconds(10)
Movey.AutoReverse = True
Movey.RepeatBehavior = RepeatBehavior.Forever
Movey.Duration = TimeSpan.FromSeconds(10)
pathf.StartPoint = New Point(0, 0)
pline.Points.Add(New Point(150, 0))
pline.Points.Add(New Point(150, 50))
pline.Points.Add(New Point(0, 50))
pline.Points.Add(New Point(0, 100))
pline.Points.Add(New Point(300, 100))
pline.Points.Add(New Point(300, 0))
pline.Points.Add(New Point(450, 0))
pline.Points.Add(New Point(450, 150))
pline.Points.Add(New Point(0, 150))
pline.Points.Add(New Point(0, 300))
pline.Points.Add(New Point(150, 300))
pline.Points.Add(New Point(150, 200))
pline.Points.Add(New Point(450, 200))
pline.Points.Add(New Point(450, 250))
pline.Points.Add(New Point(300, 250))
pline.Points.Add(New Point(300, 300))
pline.Points.Add(New Point(450, 300))
pathf.Segments.Add(pline)
Pathg.Figures.Add(pathf)
Movex.PathGeometry = Pathg
Movex.Source = PathAnimationSource.X
Movey.PathGeometry = Pathg
Movey.Source = PathAnimationSource.Y
Storyboard.SetTargetName(Movex, "trxy")
Storyboard.SetTargetProperty(Movex, New PropertyPath(trxy.XProperty))
Storyboard.SetTargetName(Movey, "trxy")
Storyboard.SetTargetProperty(Movey, New PropertyPath(trxy.YProperty))
st.Children.Add(Movex)
st.Children.Add(Movey)
TxtBlock.RenderTransform = trxy
AddHandler TxtBlock.Loaded, Sub(sender As Object, e As RoutedEventArgs) st.Begin(Me)
End Sub
Private Sub Setlinescpoint(ByVal pline As PolyLineSegment, ByVal mex As Double, ByVal mey As Double)
Dim scx As Double = Me.RenderSize.Width / mex
Dim scy As Double = Me.RenderSize.Height / mey
For Each p As Point In pline.Points
p.X *= scx
p.Y *= scy
Next
End Sub
Private Sub MainWindow_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
Setlinescpoint(Movex.PathGeometry.Figures.Item(0). Segments.Item(0), 450, 300)
Setlinescpoint(Movey.PathGeometry.Figures.Item(0). Segments.Item(0), 450, 300)
End Sub
Private Sub MainWindow_StateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.StateChanged
Setlinescpoint(Movex.PathGeometry.Figures.Item(0). Segments.Item(0), 450, 300)
Setlinescpoint(Movey.PathGeometry.Figures.Item(0). Segments.Item(0), 450, 300)
End Sub
بچه ها کمک کنید...:افسرده:
Saman_12
دوشنبه 24 بهمن 1390, 22:23 عصر
تالار که کم کار هست اما اینا دیگه پیش پا افتاده شدن (با تشکر از msdn و پشتکار خودم) :
واسه این کار کافی بود که pathgeometry رو scale بدیم اما جالبش اینجا بود که کار نمیکرد حالا چرا؟ چون وقتی یه stroyboard شروع بشه تغییر مقادیرش اثر نمیکنه من که تو یه تابع جفت storybord ها رو پاک کردم و جاش یکی جدیدش رو ساختم اینجوری :
Private Sub Scalepathg(ByVal obj As Object, ByVal pg As PathGeometry, ByVal mex As Double, ByVal mey As Double)
Dim scx, scy As Double
If Not Me.RenderSize.Width = Me.Width Or Not Me.RenderSize.Height = Me.Height Then
scx = Me.RenderSize.Width / mex
scy = Me.RenderSize.Height / mey
Else
scx = Me.Width / mex
scy = Me.Height / mey
End If
pg.Transform = New ScaleTransform((scx), (scy))
obj.FontSize = ((scx + scy) / 2) * 12
End Sub
Private Sub beginstonotherone(ByVal bestx As BeginStoryboard, ByVal besty As BeginStoryboard, ByVal du As Duration, ByVal obj As Object)
'bestx.Storyboard.Remove(obj)
'besty.Storyboard.Remove(obj)
Dim Movex, Movey As New DoubleAnimationUsingPath
Dim trxy As TranslateTransform = obj.RenderTransform
Dim pathg As PathGeometry = Me.Resources.Item("Pg")
Dim st As New Storyboard
Scalepathg(obj, pathg, 450, 300)
Movex.AutoReverse = True
Movex.RepeatBehavior = RepeatBehavior.Forever
Movex.Duration = du
Movey.AutoReverse = True
Movey.RepeatBehavior = RepeatBehavior.Forever
Movey.Duration = du
Movex.PathGeometry = pathg
Movex.Source = PathAnimationSource.X
Movey.PathGeometry = pathg
Movey.Source = PathAnimationSource.Y
Storyboard.SetTargetName(Movex, "Animetr" + obj.Name)
Storyboard.SetTargetProperty(Movex, New PropertyPath(trxy.XProperty))
Storyboard.SetTargetName(Movey, "Animetr" + obj.Name)
Storyboard.SetTargetProperty(Movey, New PropertyPath(trxy.YProperty))
st.Children.Add(Movex)
st.Children.Add(Movey)
obj.RenderTransform = trxy
bestx.Storyboard = st
besty.Storyboard = st
st.Begin(obj)
End Sub
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.