I am trying to create three paths (orbital paths) and get three ellipses (planets, rings) to travel along them, I have followed a few different blogs and forum posts but I cannot see why the ellipses are not travelling on the path.
Here is the xaml:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize"
Title="Window2" Width="800" Height="600">
<Window.Resources>
<PathGeometry x:Key="smallGeo" Figures="M 400,250C 427.614,250 450,272.386 450,300C 450,327.614 427.614,350 400,350C 372.386,350 350,327.614 350,300C 350,272.386 372.386,250 400,250"/>
<PathGeometry x:Key="mediumGeo" Figures="M 400,245C 430.376,245 455,269.624 455,300C 455,330.376 430.376,355 400,355C 369.624,355 345,330.376 345,300C 345,269.624 369.624,245 400,245"/>
<PathGeometry x:Key="largeGeo" Figures="M 400,240C 433.137,240 460,266.863 460,300C 460,333.137 433.137,360 400,360C 366.863,360 340,333.137 340,300C 340,266.863 366.863,240 400,240"/>
</Window.Resources>
<Grid Width="800" Height="600" HorizontalAlignment="Center" VerticalAlignment="Center">
<Canvas>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<!-- Small orbit animation -->
<DoubleAnimationUsingPath
Storyboard.TargetName="smallEllipse"
Storyboard.TargetProperty="(Canvas.Left)"
PathGeometry="{StaticResource smallGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="X"/>
<DoubleAnimationUsingPath
Storyboard.TargetName="smallEllipse"
Storyboard.TargetProperty="(Canvas.Top)"
PathGeometry="{StaticResource smallGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="Y"/>
<!-- Medium orbit animation -->
<DoubleAnimationUsingPath
Storyboard.TargetName="mediumEllipse"
Storyboard.TargetProperty="(Canvas.Left)"
PathGeometry="{StaticResource mediumGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="X"/>
<DoubleAnimationUsingPath
Storyboard.TargetName="mediumEllipse"
Storyboard.TargetProperty="(Canvas.Top)"
PathGeometry="{StaticResource mediumGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="Y"/>
<!-- Large orbit animation -->
<DoubleAnimationUsingPath
Storyboard.TargetName="largeEllipse"
Storyboard.TargetProperty="(Canvas.Left)"
PathGeometry="{StaticResource largeGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="X"/>
<DoubleAnimationUsingPath
Storyboard.TargetName="largeEllipse"
Storyboard.TargetProperty="(Canvas.Top)"
PathGeometry="{StaticResource largeGeo}"
Duration="0:0:5"
RepeatBehavior="Forever"
Source="Y"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<Ellipse x:Name="smallEllipse" Height="20" Stroke="Green" StrokeThickness="5" Width="20" RenderTransformOrigin="0.5,0.5"/>
<Ellipse x:Name="mediumEllipse" Height="40" Stroke="Red" StrokeThickness="5" Width="40" RenderTransformOrigin="0.5,0.5"/>
<Ellipse x:Name="largeEllipse" Height="60" Stroke="Blue" StrokeThickness="5" Width="60" RenderTransformOrigin="0.5,0.5"/>
<Path Stroke="Green" Data="{StaticResource smallGeo}"/>
<Path Stroke="Red" Data="{StaticResource mediumGeo}"/>
<Path Stroke="Blue" Data="{StaticResource largeGeo}"/>
</Canvas>
</Grid>
I used MS expression design to create the paths and kaxaml to preview the xaml.
I suspect that the Animation is not taking into account the Size of the Ellipse as its animating using the Top/Left of the Ellipse not the center of the Ellipse
One way around this would be to set the Margin of the Ellipse to negative half of the Size
Example:
<Ellipse x:Name="smallEllipse" Margin="-10" Height="20" Width="20" ......./>
<Ellipse x:Name="mediumEllipse" Margin="-20" Height="40" Width="40" ......./>
<Ellipse x:Name="largeEllipse" Margin="-30" Height="60" Width="60" ......../>
Result:
Before: After :
Related
I strted to play around with shapes in wpf, I need the following: I have an image and I draw some shape, I want the the image would walk on the lines of this shape.
I mean like:
For example with the shape:
<Path Stroke="Black" StrokeThickness="5" Fill="Goldenrod">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="100,50" IsClosed="True">
<LineSegment Point="140,60"/>
<LineSegment Point="150,100"/>
<LineSegment Point="125,120"/>
<LineSegment Point="90,110"/>
<LineSegment Point="80,80"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
And here is the moving image:
<UserControl ...
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" ..>
<UserControl.Resources>
<PathGeometry x:Key="AnimationPath"
Figures="M 10,100 C 40,0 300,0 300,300 0,300 285,200 300,300 "
PresentationOptions:Freeze="True" />
</UserControl.Resources>
<Image
Source="/Resources/Myimage.png"
Width="200" >
<Image.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform" />
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Path.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<!-- Animates the rectangle horizotally along the path. -->
<DoubleAnimationUsingPath
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="X"
PathGeometry="{StaticResource AnimationPath}"
Source="X"
Duration="0:0:5"
AutoReverse="True"
/>
<!-- Animates the rectangle vertically along the path. -->
<DoubleAnimationUsingPath
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="Y"
PathGeometry="{StaticResource AnimationPath}"
Source="Y"
Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
Related links: link1, link2
I have tried like:
Figures="M 10,100 C 100,50 140,60 150,100 125,120 90,110 80,80 "
i.e start at point 100,50 --> 140,60 and so on...
but it doesnt go exactly on this path
Your sketch seems to indicate that you want to animate kind of a red arrow along the path, including a rotation to the tangent angle of the current path segment.
You could achieve this by animating the Matrix property of a MatrixTransform with a MatrixAnimationUsingPath. The example below uses an additional TranslateTransform to center the image. As there is a DrawingImage in the Source property of the Image element, you may as well use another Path instead of an Image.
<Window.Resources>
<PathGeometry x:Key="AnimationPath"
Figures="M100,50 L140,60 150,100 125,120 90,110 80,80Z"/>
</Window.Resources>
<Canvas>
<Path Stroke="Black" StrokeThickness="5" Fill="Goldenrod"
Data="{StaticResource AnimationPath}"/>
<Image>
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Geometry="M0,0 L10,8 0,16">
<GeometryDrawing.Pen>
<Pen Thickness="3" Brush="Red"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
<Image.RenderTransform>
<TransformGroup>
<TranslateTransform X="-5" Y="-8"/>
<MatrixTransform x:Name="AnimatedTransform"/>
</TransformGroup>
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<MatrixAnimationUsingPath
Storyboard.TargetName="AnimatedTransform"
Storyboard.TargetProperty="Matrix"
Duration="0:0:5"
DoesRotateWithTangent="True"
PathGeometry="{StaticResource AnimationPath}"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</Canvas>
I was trying to make Flip Animation in XAML in WPF but was not as I wanted and I am not able to find the required answer. Only thing I could make was Scale the Image(XAML code is below) but it was not looking like flip. Please tell me what is needed for Flip Animation.
<Rectangle x:Name="Image" Fill="DarkSeaGreen" RenderTransformOrigin="0.5,0.5" Height="150" Width="200" Canvas.Left="150" Canvas.Top="150">
<Rectangle.RenderTransform>
<ScaleTransform ScaleY="-1" />
</Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="ImageFlip">
<DoubleAnimation From="-1" To="1" BeginTime="0:0:1" Duration="0:0:2" Storyboard.TargetName="Image" Storyboard.TargetProperty="(RenderTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
If you want it to look like it's flipping then you need to skew the object so what would be the furthest edge is narrower
Like this:
<Rectangle x:Name="Image" Fill="DarkSeaGreen"
RenderTransformOrigin="0.5,0.5" Height="150" Width="200">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="ImageFlip">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.0" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.09" Value="0.3" />
<SplineDoubleKeyFrame KeyTime="00:00:00.12" Value="0.6" />
<SplineDoubleKeyFrame KeyTime="00:00:00.15" Value="0.8" />
<SplineDoubleKeyFrame KeyTime="00:00:00.18" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00.0" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.09" Value="0.9" />
<SplineDoubleKeyFrame KeyTime="00:00:00.18" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />
<SplineDoubleKeyFrame KeyTime="00:00:00.06" Value="-10" />
<SplineDoubleKeyFrame KeyTime="00:00:00.09" Value="-20" />
<SplineDoubleKeyFrame KeyTime="00:00:00.1" Value="20" />
<SplineDoubleKeyFrame KeyTime="00:00:00.18" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
You might find this interesting:
https://archive.codeplex.com/?p=flipcontrol
You need a scale transform for Y-axis running from 1 to -1. My WPF-fu is pretty outdated so I can't give you the exact transform XAML.
<UserControl x:Class="FlipControl.FlipControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<Storyboard x:Key="StoryFlip">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(AxisAngleRotation3D.Angle)"
Storyboard.TargetName="rot">
<SplineDoubleKeyFrame KeyTime="00:00:01" KeySpline="0,0,0,1" Value="180"></SplineDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(AxisAngleRotation3D.Angle)"
Storyboard.TargetName="rot2">
<SplineDoubleKeyFrame KeyTime="00:00:01" KeySpline="0,0,0,1" Value="360"></SplineDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="StoryFlipBack">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(AxisAngleRotation3D.Angle)"
Storyboard.TargetName="rot">
<SplineDoubleKeyFrame KeyTime="00:00:01" KeySpline="0,0,0,1" Value="0"></SplineDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(AxisAngleRotation3D.Angle)"
Storyboard.TargetName="rot2">
<SplineDoubleKeyFrame KeyTime="00:00:01" KeySpline="0,0,0,1" Value="180"></SplineDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0, 0, 4"/>
</Viewport3D.Camera>
<Viewport2DVisual3D x:Name="Side1">
<!-- Rotation definieren -->
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D x:Name="rot" Angle="0" Axis="1, 0, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform>
<!-- Geometry und Material für das Viewport2DVisual3D -->
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 0 2 3" />
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
</Viewport2DVisual3D.Material>
</Viewport2DVisual3D>
<Viewport2DVisual3D x:Name="Side2">
<!-- Rotation definieren -->
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D x:Name="rot2" Angle="180" Axis="1, 0, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform>
<!-- Geometry und Material für das Viewport2DVisual3D -->
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 0 2 3" />
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
</Viewport2DVisual3D.Material>
<!-- Steuerelemente in 3D-Look -->
</Viewport2DVisual3D>
<!-- Licht -->
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</UserControl>
Add properties
public Visual FrontSide
{
get
{
return Side1.Visual;
}
set
{
UIElement Elem;
Storyboard Animation;
Side1.Visual = value;
Elem = Side1.Visual as UIElement;
if (Elem != null)
{
Elem.MouseEnter += (sender, e) =>
{
Animation = this.Resources["StoryFlip"] as Storyboard;
if (Animation != null)
{
Animation.Begin();
}
};
}
}
}
public Visual BackSide
{
get
{
return Side2.Visual;
}
set
{
UIElement Elem;
Storyboard Animation;
Side2.Visual = value;
Elem = Side2.Visual as UIElement;
if (Elem != null)
{
Elem.MouseLeave += (sender, e) =>
{
Animation = this.Resources["StoryFlipBack"] as Storyboard;
if (Animation != null)
{
Animation.Begin();
}
};
}
}
}
add front ad flip side
Mario Meir-Huber</TextBlock>
You can do a lot of</TextBlock>
Things with this Control!</TextBlock>-->
<flip:FlipControl.BackSide>
<StackPanel>
<Border BorderThickness="2" BorderBrush="Red">
<Button Height="20" Width="40"></Button>
</Border>
<!--<TextBlock>You want to send me an E-Mail?</TextBlock>
<TextBox Height="80" AcceptsReturn="True"></TextBox>
<Button>Just do it!</Button>
<TextBlock>mario#meirhuber.de</TextBlock>-->
</StackPanel>
</flip:FlipControl.BackSide>
</flip:FlipControl>
</Border>
<Border Width="150" Height="150">
<flip:FlipControl MouseEnter="FlipControl_MouseEnter" MouseLeave="FlipControl_MouseLeave" Name="FlipMe1">
<flip:FlipControl.FrontSide>
<StackPanel Height="20" Width="40">
<Border BorderThickness="2" BorderBrush="Green">
<Button Height="20" Width="40"></Button>
</Border>
<!--<TextBlock FontSize="16" Foreground="Blue">Mario Meir-Huber</TextBlock>
<Line X1="0" X2="130" StrokeThickness="2" Stroke="Black" />
<TextBlock FontSize="6">You can do a lot of</TextBlock>
<TextBlock FontSize="6">Things with this Control!</TextBlock>-->
</StackPanel>
</flip:FlipControl.FrontSide>
<flip:FlipControl.BackSide>
<StackPanel>
<Border BorderThickness="2" BorderBrush="Red">
<Button Height="20" Width="40"></Button>
</Border>
<!--<TextBlock>You want to send me an E-Mail?</TextBlock>
<TextBox Height="80" AcceptsReturn="True"></TextBox>
<Button>Just do it!</Button>
<TextBlock>mario#meirhuber.de</TextBlock>-->
</StackPanel>
</flip:FlipControl.BackSide>
</flip:FlipControl>
</Border>
<Border Width="150" Height="150">
<flip:FlipControl MouseEnter="FlipControl_MouseEnter" MouseLeave="FlipControl_MouseLeave" Name="FlipMe2">
<flip:FlipControl.FrontSide>
<StackPanel Height="20" Width="40">
<Border BorderThickness="2" BorderBrush="Green">
<Button Height="20" Width="40"></Button>
</Border>
<!--<TextBlock FontSize="16" Foreground="Blue">Mario Meir-Huber</TextBlock>
<Line X1="0" X2="130" StrokeThickness="2" Stroke="Black" />
<TextBlock FontSize="6">You can do a lot of</TextBlock>
<TextBlock FontSize="6">Things with this Control!</TextBlock>-->
</StackPanel>
</flip:FlipControl.FrontSide>
<flip:FlipControl.BackSide>
<StackPanel>
<Border BorderThickness="2" BorderBrush="Red">
<Button Height="20" Width="40"></Button>
</Border>
<!--<TextBlock>You want to send me an E-Mail?</TextBlock>
<TextBox Height="80" AcceptsReturn="True"></TextBox>
<Button>Just do it!</Button>
<TextBlock>mario#meirhuber.de</TextBlock>-->
</StackPanel>
</flip:FlipControl.BackSide>
</flip:FlipControl>
</Border>
</WrapPanel>
I've been playing around with some basic WPF Storyboard animation and it looks quite blurry, it's Ok up to a certain speed then really degrades into blurryness.
Is there anyway I can get it to look smoother? - increase the framerate somehow or maybe double buffer the animation?
I've tried setting the objects to CacheMode="BitmapCache" but this seems to have little effect.
Does anyone have any ideas please?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="1000" Height="600" >
<Window.Triggers>
<EventTrigger RoutedEvent="UserControl.Loaded" >
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation From="600" To="-600" Duration="00:00:02"
Storyboard.TargetName="MyObject"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid Name="MyObject">
<Grid.RenderTransform>
<TranslateTransform X="0" />
</Grid.RenderTransform>
<Ellipse Stroke="Black" Fill="Green" StrokeThickness="3" Width="100" Height="250" />
<Ellipse Stroke="Black" Fill="White" StrokeThickness="3" Width="80" Height="180" />
</Grid>
</Grid>
</Window>
You could try increasing the FrameRate:
MediaTimeline.DesiredFrameRateProperty.OverrideMetadata(typeof(System.Windows.Media.Animation.Timeline), new FrameworkPropertyMetadata(60));
The higher the number, the higher the framerate (the smoother the execution). Be cautious though, higher framerates impact performance!
I hope this helps.
Below is the data template I'm using for a listbox's ItemTemplate. It shows some simple data, and a button, which ideally should animate a Popup, also contained within the DataTemplate. Unfortunately the whole thing blow up at runtime. The error says line 52 is wrong, which is:
<EventTrigger RoutedEvent="Button.Click">
Here's the whole DataTemplate. I've used this popup before, with the same exact content templates and even the same animation elsewhere. It's only blowing up when I try to put it into a DataTemplate. I assume the animation is having difficulty finding the right animation target - I'm hoping someone here would know more.
<DataTemplate x:Key="ItemTemplate2">
<Border Width="100" Height="100" BorderThickness="4" BorderBrush="Red">
<StackPanel>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Price}"/>
<Popup x:Name="popupContent" IsOpen="True" Margin="10,0,0,0" Grid.Row="0" >
<Popup.Child>
<Thumb x:Name="thumbContent" DragDelta="Thumb_DragDelta" Width="0" Height="0">
<Thumb.Template>
<ControlTemplate>
<local:thumbTemplate Margin="0" x:Name="df" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Popup.Child>
</Popup>
<Button Content="Show">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<BeginStoryboard.Storyboard>
<Storyboard x:Name="sbShowPopup">
<DoubleAnimation Duration="0:0:1" To="200" Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="popupContent" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:1" To="80" Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="popupContent" d:IsOptimized="True"/>
</Storyboard>
</BeginStoryboard.Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
</Border>
</DataTemplate>
You may have used this before but not in Silverlight. The only supported value for RoutedEvent in Silverlight is "FrameworkElement.LoadedEvent".
You will need the BlendSDK to do this sort of thing in Silverlight.
I'm struggling to get a PropertyPath to work - I've got a Transformation in the Window Resources that I'm trying to affect via a StoryBoard - also in Window Resources ...
Heres the property path i'm using ...
(Viewport2DVisual3D.Transform).(Transform3DGroup)[0].(RotateTransform3D).(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)
EDIT: Thanks to Anurags suggestion I've got a bit further ...
(Viewport2DVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)
but now it errors with "Rotation property does not point to a DependencyProperty"
Can anyone please put me back on track?
Heres the code in full ...
<Window
x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Window.Resources>
<Transform3DGroup x:Key="WorldTranslation">
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
<Storyboard x:Key="MyStoryboard">
<DoubleAnimation
Storyboard.Target="{Binding TemplatedParent}"
Storyboard.TargetProperty="(Viewport2DVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"
From="0.0" To="360" Duration="0:0:1" />
</Storyboard>
<MeshGeometry3D
x:Key="squareMeshFrontLeft"
Positions="-1,-1,1 1,-1,1 1,1,1 -1,1,1"
TriangleIndices="0 1 2 0 2 3"
TextureCoordinates="0,1 1,1 1,0 0,0" />
<DiffuseMaterial x:Key="visualHostMaterial" Brush="White" Viewport2DVisual3D.IsVisualHostMaterial="True" />
</Window.Resources>
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,10" LookDirection="0,0,-1" />
</Viewport3D.Camera>
<Viewport2DVisual3D Material="{StaticResource visualHostMaterial}" Geometry="{StaticResource squareMeshFrontLeft}" >
<Viewport2DVisual3D.Transform>
<StaticResource ResourceKey="WorldTranslation" />
</Viewport2DVisual3D.Transform>
<StackPanel Background="Blue" Width="80" Height="80">
<Button Height="30" Margin="20">
<Button.Content>Blah</Button.Content>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource MyStoryboard}" >
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
</Viewport2DVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Window>
First of all, instead of DoubleAnimation, use 3D KeyFrame Animation.
and correct your StoryBoard.TargetProperty's syntax using (Transform3DGroup.Children) instead of
check this also:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/78170274-a585-4cd6-85ed-edfd655d34ab