Monday, October 6, 2014

Changing Properties with the Storyboard (WPF)

Used with EventTriggers

<UserControl.Triggers>

     <EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="CheckboxName">
          <BeginStoryboard x:Name="OnChecked_BeginStoryboard" Storyboard="{StaticResource ShowList}"/>
     </EventTrigger>


     <EventTrigger RoutedEvent="ToggleButton.Unchecked" SourceName="CheckboxName">
          <BeginStoryboard x:Name="OnChecked_BeginStoryboard" Storyboard="{StaticResource HideList}"/>

     </EventTrigger>


</UserControl.Triggers>


ObjectAnimationUsingKeyFrames (with a DiscreteObjectKeyFrame)

Changing the ItemsSource:

<Storyboard x:key="ItemsSourceChange">
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyList"  Storyboard.TargetProperty="ItemsSource" Duration="0:0:0">
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{Binding Source={StaticResource Data}}"/>
     </ObjectAnimationUsingKeyFrames>
</Storyboard>

Changing the Style:

<Storyboard x:key="ItemsSourceChange">
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyList"  Storyboard.TargetProperty="Style" Duration="0:0:0">
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{Binding Source={StaticResource ListStyle}}"/>
     </ObjectAnimationUsingKeyFrames>
</Storyboard>

Changing the Visibility:

<Storyboard x:key="ShowList">
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyList"  Storyboard.TargetProperty="(UIElement.Visibility)" Duration="0:0:0">
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
     </ObjectAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:key="HideList">
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyList"  Storyboard.TargetProperty="(UIElement.Visibility)" Duration="0:0:0">
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
     </ObjectAnimationUsingKeyFrames>
</Storyboard>

BooleanAnimationUsingKeyFrames (with a DiscreteBooleanKeyFrame)

Changing the IsChecked on a checkbox:

<Storyboard x:key="ChangeIsChecked">
     <BooleanAnimationUsingKeyFrames Storyboard.TargetName="CheckBox2"  Storyboard.TargetProperty="IsChecked" Duration="0:0:0">
          <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False"/>
     </BooleanAnimationUsingKeyFrames >
</Storyboard>

No comments:

Post a Comment