ここでは、以下のコードのようにこのトグルボタンがあります。このトグルボタンにはcontrol template
も定義されています。状況によっては、このボタンが無効になっています。すなわち、ボタン上のI cannot click
。私はMVVM
パターンに従っています。私はブレークポイントを入れてチェックしました。ボタンIsEnabled
の状態を変更することには何も関係しません。トグルボタンがどのように無効になっているのかわかりません
私はボタンの有効状態がどのように変化しているか把握しようとしています。ボタンの有効な状態の変更やそれに関連するものは何もありません。 したがって、ここでは不要なコードを表示/表示することはありません。
XAMLコードからボタンの状態がどのように無効に変更されているか、またはそのプロパティがその変更につながっているかを知ることができれば、非常に役に立ちます。前もって感謝します。
<ToggleButton x:Name="TestBtn"
Height="60"
Margin="5"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Command="{Binding StartStopResetCommand}"
Content="{Binding BtnState,
Converter={StaticResource BtnTextConverter}}"
FontSize="16"
Foreground="White"
PreviewKeyDown="BtnPreviewKeyDown">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness=".5"
SnapsToDevicePixels="true">
<ContentPresenter x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="#595959" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding BtnState}" Value="{x:Static my:ButtonState.Start}">
<Setter Property="Background" Value="{StaticResource ButtonBackgroundBrush}" />
</DataTrigger>
<DataTrigger Binding="{Binding BtnState}" Value="{x:Static my:ButtonState.Stop}">
<Setter Property="Background" Value="{StaticResource ExecutingStateColor}" />
</DataTrigger>
<DataTrigger Binding="{Binding BtnState}" Value="{x:Static my:ButtonState.Reset}">
<Setter Property="Background" Value="{StaticResource ButtonBackgroundBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
"StartStopResetCommand"アクションが "CanExecute"アクションを実装し、ある時点でfalseを返す場合、ボタンの状態は自動的に変更できます。 – Matas
** Upvote。**とても速く正確です。私はまだそのようなことを知らなかった。ありがとう。 – ViVi