<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:1" To="CheckedState" />
<VisualTransition GeneratedDuration="0:0:1" To="UnCheckedState" />
</VisualStateGroup.Transitions>
<VisualState x:Name="CheckedState">
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="#A1D6FC"
Duration="0:0:0:1" />
</Storyboard>
</VisualState>
<VisualState x:Name="UnCheckedState"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<CheckBox Content="复选框" x:Name="_checkbox">
<i:Interaction.Behaviors>
<ei:DataStateBehavior Binding="{Binding IsChecked,ElementName=_checkbox}" Value="True" TrueState="CheckedState" FalseState="UnCheckedState"/>
</i:Interaction.Behaviors>
</CheckBox>
</Grid>
在这里,我们使用Microsoft.Expression.Interactivity.Core中的DataStateBehavior实现,原理是将一个CheckBox 的IsChecked绑定 到DataStateBehavior上面,利用IsChecked属性两种状态来让当前Grid呈现不同的可视状态