Checked VisualState is not triggered after RadioButton is re-enabled

杀马特。学长 韩版系。学妹 提交于 2019-12-02 08:21:06
Nicholas Miller

Apparently, the problem is that I am using the same target properties within two different VisualStateGroups, yet I'm not sure why this causes the problem.

In order to have the desired affect, which is to display the Checked behavior after re-enabling, I created another Ellipse which is overlaid of the the original Ellipse.

The original Ellipse is fully opaque and it's Fill/Stroke properties are modified by the CheckStates group ONLY.

The new Ellipse is initially fully transparent (Opacity="0"), but the Disabled state causes the opacity to change to fully opaque.

This new Ellipse fades into into view and covers up the original Ellipse, which is showing the appearance of the Checked/Unchecked states. This causes the overall result of the RadioButton to appear Disabled.

This fixed the problem describe in the OP, but it introduces a new issue: the transition from the Disabled state to the Checked state is immediate. This can be resolve by including this VisualTransition in the CommonStates group:

<VisualTransition From="Disabled" To="Checked" GeneratedDuration="0:0:0.25"/>

Here is the final XAML used to solve the problem:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
        <VisualStateGroup.Transitions>
            <VisualTransition From="Disabled" To="Checked" GeneratedDuration="0:0:0.25"/>
        </VisualStateGroup.Transitions>
        <VisualState Name="Normal"/>
        <VisualState Name="Disabled">
            <Storyboard>
                <DoubleAnimation Storyboard.TargetName="EllipseOverlay" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.15"/>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup x:Name="CheckStates">
        <VisualState Name="Checked">
            <Storyboard>
                <ParallelTimeline>
                    <ColorAnimation Storyboard.TargetName="FillBrush" Storyboard.TargetProperty="Color" To="#FFC5F5FF" Duration="0:0:0.05"/>
                    <ColorAnimation Storyboard.TargetName="StrokeBrush" Storyboard.TargetProperty="Color" To="#FF12394F" Duration="0:0:0.05"/>
                    <DoubleAnimation Storyboard.TargetName="MoodEllipse" Storyboard.TargetProperty="StrokeThickness" To="2" Duration="0:0:0.05"/>
                </ParallelTimeline>
            </Storyboard>
        </VisualState>
        <VisualState Name="Unchecked"/>
        <VisualState Name="Indeterminate"/>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

In my control, I have this Ellipse appear after my original Ellipse, causing the new one to appear on top when the opacity increases. Below is the new Ellipse:

<Ellipse x:Name="EllipseOverlay" StrokeThickness="1" Opacity="0" Fill="#FFEEEEEE" Stroke="#FF777777"/>

Note that this Ellipse contains the Fill/Stroke properties that were using the the OP's Disabled VisualState.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!