我有一组复选框,其样式设置为类似于切换按钮,用于选择或取消选择当前用户要包含的网络中的用户。可以在运行时禁用或启用这些复选框,具体取决于用户是否可用。
为了可视化所有这些,我创建了一个带有可视状态管理器的样式,该样式具有2个VisualStateGroups,一个用于处理检查和取消检查,一个用于处理禁用状态。第一次禁用复选框然后再次启用复选框时,所有这些都可以正常工作。 但是,当我第二次禁用该复选框时,它仍然停留在未选中的样式。
我已经尝试过Checked VisualState is not triggered after RadioButton is re-enabled中提供的解决方案以及他的How to keep the ToggleButton status after re-enable中的第一个答案,但是我仍然遇到相同的问题。同样,第一个解决方案使它看起来更难看,所以我再次将其还原。
我的VisualStateManager:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimationUsingPath
Storyboard.TargetName="ellipseAnim"
Storyboard.TargetProperty="X"
PathGeometry="{StaticResource pathCheck}"
Source="X"
Duration="00:00:00.1" />
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="grid"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="00:00:00.05" Value="{StaticResource checkBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="toggleBall"
Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="00:00:00.1" Value="{StaticResource XVR30}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="00:00:00.1" Value="{StaticResource XVR220}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked" >
<Storyboard x:Name="Uncheck">
<DoubleAnimationUsingPath
Storyboard.TargetName="ellipseAnim"
Storyboard.TargetProperty="X"
PathGeometry="{StaticResource pathUncheck}"
Source="X"
Duration="00:00:00.1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Indeterminate">
<Storyboard>
<DoubleAnimationUsingKeyFrames
BeginTime="0:0:0"
Storyboard.TargetName="toggleBall"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" >
<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="-15" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="DisabledStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="toggleBall"
Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="00:00:00.1" Value="{StaticResource XVR90}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>