Skip to content

Instantly share code, notes, and snippets.

@imwower
Created September 25, 2014 08:08
Show Gist options
  • Save imwower/c71294efb8381d9efb22 to your computer and use it in GitHub Desktop.
Save imwower/c71294efb8381d9efb22 to your computer and use it in GitHub Desktop.
visual state manager helper
{
/// <summary>
/// Copied from http://stackoverflow.com/questions/6002046/binding-visualstatemanager-view-state-to-a-mvvm-viewmodel
/// </summary>
public class StateHelper : DependencyObject
{
public static readonly DependencyProperty StateProperty = DependencyProperty.RegisterAttached(
"State", typeof(String), typeof(StateHelper), new PropertyMetadata("Normal", StateChanged));
internal static void StateChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
{
string newState = (string)args.NewValue;
if (args.NewValue != null)
{
bool res = VisualStateManager.GoToElementState((FrameworkElement)target, newState, true);
}
}
public static void SetState(DependencyObject obj, string value)
{
obj.SetValue(StateProperty, value);
}
public static string GetState(DependencyObject obj)
{
return (string)obj.GetValue(StateProperty);
}
}
}
<Border x:Name="ellipse" local:StateHelper.State="{Binding Path=State}"
HorizontalAlignment="Left" Height="116" Margin="74,43,0,0"
VerticalAlignment="Top" Width="122" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Full">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="127"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border.Background>
<SolidColorBrush x:Name="brush" Color="Black" />
</Border.Background>
</Border>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment