私はRadioButton
、ユーザーが選択しRadioButton
た .
ただし、私のアプリケーションでは、5 つRadioButtons
が無効になってから再び有効になる場合があります。これが発生するVisualState
と、Checked RadioButton
がアクティブになりません。代わりに、5 つすべてが通常の状態RadioButtons
として表示されます。
なぜこうなった?どうすればこれを解決できますか?
RadioButtons
これが私が使用しているの例です。
5 の最初のグループを選択することから始めて、選択RadioButtons
を行うと、上の画像のようにすべてが表示される場合があります。
しかし、5 の 2 番目のグループを選択するRadioButtons
と、最初のグループが無効になるようにコントロールが設計されています。これは正常に機能し、2 番目のグループが適切に有効になります。その後、最初のグループを再度選択すると、すべてRadiobutton
がNormal VisualStateで表示されます。私のプログラムは#1がまだCheckedであることを舞台裏で知っているので、これは問題です。Checked VisualStateはトリガーされないため、次のようになります。
ここでの目標は、最初の画像に表示されているようにChecked VisualState
が再開されることです。
に対応する XAML コードは次のVisualStates
とおりです。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState Name="Normal"/>
<VisualState Name="Disabled">
<Storyboard>
<ColorAnimation Storyboard.TargetName="FillBrush" Storyboard.TargetProperty="Color" To="#FFEEEEEE" Duration="0"/>
<ColorAnimation Storyboard.TargetName="StrokeBrush" Storyboard.TargetProperty="Color" To="#FF777777" Duration="0"/>
<DoubleAnimation Storyboard.TargetName="MoodEllipse" Storyboard.TargetProperty="StrokeThickness" To="1" Duration="0"/>
<ColorAnimation Storyboard.TargetName="Presenter" Storyboard.TargetProperty="(TextBlock.Foreground).Color" To="#FF777777" Duration="0"/>
</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>
この XAML コードは の使い方に従っているようですVisualStates
が、何か問題があるのではないでしょうか。
これらのページを参照しました:
追加のメモとして、 Uncheckedのいずれかをクリックすると、 Checked がトリガーされる可能性があることに気付きました。この時点で、グループが無効化されて再度有効化されるまで、すべてが正常に動作します。VisualState
RadioButtons
RadioButtons
また、上記の XAML コードに空のUncheckedを含めなかった場合、 Checked のさらに奇妙な動作を経験しました。VisualState
VisualState
が奇妙な動作をしている理由についての洞察をVisualStates
いただければ幸いです。どうもありがとう!
編集:
それが問題かどうかはわかりませんが、のグループRadioButtons
は無効になっています。これは、StackPanels
そのプロパティが outsideのプロパティIsEnabled
にバインドされているためです。RadioButton
IsChecked
<StackPanel IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type RadioButton}}, Path=IsChecked}">