Reputation: 97
I was wrote a custom template for checkbox control that it display green for checked and display red for unchecked.I want to the checkbox control make itself disabled for 3 seconds after trigger check/uncheck event and then recover itself enabled.How can I integrate the function to my custom template?
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid1">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="grid">
<Rectangle HorizontalAlignment="Left" Height="22" Stroke="White" VerticalAlignment="Top" Width="22">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FF86CC6E" Offset="0.022"/>
<GradientStop Color="#FF47E211" Offset="0.81"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" FontFamily="Arial Black" FontSize="10.667" Text="{TemplateBinding Content}" />
</Grid>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
<Grid x:Name="grid1">
<Rectangle HorizontalAlignment="Left" Height="22" Stroke="White" VerticalAlignment="Top" Width="22">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FFDE6666" Offset="0.022"/>
<GradientStop Color="#FFFB2611" Offset="0.81"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" FontFamily="Arial Black" FontSize="10.667" Text="{TemplateBinding Content}" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Upvotes: 2
Views: 602
Reputation: 63317
There is at least a way using Trigger
like this:
<ControlTemplate TargetType="{x:Type CheckBox}">
<ControlTemplate.Resources>
<Storyboard x:Key="ffIsEnabled" Storyboard.TargetProperty="IsEnabled">
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
<DiscreteBooleanKeyFrame KeyTime="0:0:3" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ffIsEnabled}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource ffIsEnabled}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
<!-- ... -->
</ControlTemplate>
Upvotes: 2