Expression Blend と呼ばれる小さなチートでそれを行いました。しかし、あなたはそれがどのように行われたかを見ることができます. 選択肢は常にあります。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="CollapseTriangel">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.748"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.496"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="0.195"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-0.007"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="path">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="20.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="40.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="64.75"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="81"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="ExpandTriangel">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
<SplineDoubleKeyFrame KeyTime="0:0:0.4" Value="0.195"/>
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="0.496"/>
<SplineDoubleKeyFrame KeyTime="0:0:1.5" Value="0.748"/>
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="path">
<SplineDoubleKeyFrame KeyTime="0:0:0.4" Value="64.75"/>
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="40.5"/>
<SplineDoubleKeyFrame KeyTime="0:0:1.5" Value="20.25"/>
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
<EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="checkBox">
<BeginStoryboard x:Name="CollapseTriangel_BeginStoryboard" Storyboard="{StaticResource CollapseTriangel}"/>
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked" SourceName="checkBox">
<BeginStoryboard x:Name="ExpandTriangel_BeginStoryboard" Storyboard="{StaticResource ExpandTriangel}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<Path x:Name="path" Data="M159.5,239.5 L399.5,239.5 279.5,79.5 z" Fill="#FF0202FF" Margin="159.5,79.5,223.5,201.5" Stretch="Fill" Stroke="Black" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
</Path>
<CheckBox x:Name="checkBox" Content="CheckBox" HorizontalAlignment="Left" Margin="80,0,0,201.5" VerticalAlignment="Bottom"/>
</Grid>
</Window>
ストーリーボードがある場合は、いつでもトリガーを変更できます。
ブール値に基づいて、必要に応じて。たとえば、次のようにします。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="CollapseTriangel">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.748"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.496"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="0.195"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-0.007"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="path">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="20.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="40.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="64.75"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="81"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="ExpandTriangel">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
<SplineDoubleKeyFrame KeyTime="0:0:0.4" Value="0.195"/>
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="0.496"/>
<SplineDoubleKeyFrame KeyTime="0:0:1.5" Value="0.748"/>
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="path">
<SplineDoubleKeyFrame KeyTime="0:0:0.4" Value="64.75"/>
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="40.5"/>
<SplineDoubleKeyFrame KeyTime="0:0:1.5" Value="20.25"/>
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Control>
<Control.Template>
<ControlTemplate>
<Grid x:Name="LayoutRoot">
<Path x:Name="path" Data="M159.5,239.5 L399.5,239.5 279.5,79.5 z" Fill="#FF0202FF" Margin="159.5,79.5,223.5,201.5" Stretch="Fill" Stroke="Black" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
</Path>
<CheckBox x:Name="checkBox" Content="CheckBox" HorizontalAlignment="Left" Margin="80,0,0,201.5" VerticalAlignment="Bottom"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="checkBox" Property="IsChecked" Value="True">
<Trigger.EnterActions>
<BeginStoryboard x:Name="CollapseTriangel_BeginStoryboard" Storyboard="{StaticResource CollapseTriangel}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard x:Name="ExpandTriangel_BeginStoryboard" Storyboard="{StaticResource ExpandTriangel}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Control.Template>
</Control>
</Window>
編集
もう1つ心に留めておいてください。トリガーを要素に直接適用したい場合は、EventTrigger
. orを使用したい場合は、Trigger
orDataTrigger
に入れる必要がありStyle
ますControlTemplate
。Control
そのため、2 番目の例に追加しました。