Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2015 01:12
Show Gist options
  • Save anonymous/267c85e546ae4ac1f7c2 to your computer and use it in GitHub Desktop.
Save anonymous/267c85e546ae4ac1f7c2 to your computer and use it in GitHub Desktop.
// Using a DependencyProperty as the backing store for CardValue. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CardPlayedProperty =
DependencyProperty.Register("CardPlayed", typeof(bool), typeof(SelectableCard), new PropertyMetadata(false, UpdateCardPlayed));
private static void UpdateCardPlayed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as SelectableCard).CardPlayedChanged((bool)e.NewValue);
}
private void CardPlayedChanged(bool newValue)
{
if (newValue)
VisualStateManager.GoToState(this, "Played", true);
else
{
if (IsEnabled)
VisualStateManager.GoToState(this, "Normal", true);
else
VisualStateManager.GoToState(this, "Active", true);
}
}
<UserControl
x:Class="Cribbage.SelectableCard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Cribbage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400" IsEnabledChanged="HandleEnabledChangd" Loaded="InitializeState">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TapStates">
<VisualState x:Name="PointerDown">
<Storyboard>
<PointerDownThemeAnimation TargetName="ContentGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="PointerUp">
<Storyboard>
<PointerUpThemeAnimation TargetName="ContentGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="HighlightBrush" Storyboard.TargetProperty="Color" To="GreenYellow" Duration="0:0:0.5"/>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseLeave">
<Storyboard>
<ColorAnimation Storyboard.TargetName="HighlightBrush" Storyboard.TargetProperty="Color" To="Transparent" Duration="0:0:0.5"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Initial">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid"
Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="1" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid"
Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="1" />
</ObjectAnimationUsingKeyFrames>
<ColorAnimation Storyboard.TargetName="StatusColorBrush" Storyboard.TargetProperty="Color" To="LimeGreen" Duration="0:0:0.5"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid"
Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="0.25" />
</ObjectAnimationUsingKeyFrames>
<ColorAnimation Storyboard.TargetName="StatusColorBrush" Storyboard.TargetProperty="Color" To="WhiteSmoke" Duration="0:0:0.5"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Played">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid"
Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="0.25" />
</ObjectAnimationUsingKeyFrames>
<ColorAnimation Storyboard.TargetName="StatusColorBrush" Storyboard.TargetProperty="Color" To="Red" Duration="0:0:0.5"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border BorderThickness="5" x:Name="HighlightBorder" CornerRadius="37">
<Border.BorderBrush>
<SolidColorBrush x:Name="HighlightBrush" Color="Transparent"/>
</Border.BorderBrush>
<Border BorderThickness="7" x:Name="ContentGrid" CornerRadius="32">
<Border.BorderBrush>
<SolidColorBrush x:Name="StatusColorBrush" Color="WhiteSmoke"/>
</Border.BorderBrush>
<Grid>
<Image x:Name="CardDisplay"/>
</Grid>
</Border>
</Border>
</Grid>
</UserControl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment