あなたはディスエーブル制御でイベントをトリガすることができなくなりますので、私はあなたのためにそれを処理するた、その上に透明の四角形を配置勧め:
<Button x:Name="Button1" IsEnabled="False"/>
<Rectangle Opacity="0" Fill="Transparent">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Button1, Path=IsEnabled}"
Value="False">
<Setter Property="Cursor" Value="No"/>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
ボタンがないときに矩形が折りたたまれていますボタンイベントがトリガーできるようになりました。ボタンが有効になると、四角形が表示され(0の不透明度と透明な背景で表示されます)、マウスオーバーするとカーソルが表示されなくなります。
編集:ここでは
<Window x:Class="WpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
HorizontalAlignment="Center">
<!-- Regular Button-->
<Button Width="120" Height="22" Margin="5"/>
<!--Custom Button-->
<Grid Width="120" Height="22" Margin="5">
<Button x:Name="Button1" IsEnabled="False"/>
<Rectangle Opacity="0" Fill="Transparent">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Button1, Path=IsEnabled}"
Value="False">
<Setter Property="Cursor" Value="No"/>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Grid>
</StackPanel>
</Grid>
</Window>
デモです:コメントパー
、ここでワーキングサンプル(も問題のOPを解決しようとする有効ボタンキャンセル行動を持っている)です
を
同様のXAMLを使用してカスタムコントロールを作成することをおすすめします。少なくとも、テンプレートを作成して再利用することができます。
これは、ユーザーにとって大きな驚きにつながるとは思いませんか? - 通常、カーソルの変更は、ユーザーが何かできることを示すものです*。 –
はい、カーソルを停止ポインタに変更すると、そのボタンに対して何の操作も実行できません。 –
私のアプリケーションをより使いやすくします。 –