ボタンの状態に応じてデザインを以下のように変更したいです。
・初期状態:ボタン背景色 赤色
・マウスオーバー:ボタン背景色 緑色
・クリック時:ボタン背景色 青色
そこでxamlで以下のようなコードを書きました。
xaml
1<Window x:Class="test.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 mc:Ignorable="d" 7 Title="MainWindow" Height="450" Width="800"> 8 9<StackPanel> 10 <Button Height="50"> 11 <Button.Template> 12 <ControlTemplate TargetType="Button"> 13 <Border Name="border" BorderThickness="1" Background="Red"> 14 <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" /> 15 </Border> 16 <ControlTemplate.Triggers> 17 <Trigger Property="IsMouseOver" Value="True"> 18 <Setter TargetName="border" Property="Background" Value="Green"></Setter> 19 </Trigger> 20 <Trigger Property="IsPressed" Value="True"> 21 <Setter TargetName="border" Property="Background" Value="Blue"></Setter> 22 </Trigger> 23 </ControlTemplate.Triggers> 24 </ControlTemplate> 25 </Button.Template> 26 </Button> 27</StackPanel>
パッと見は正しく動いているのですが、
クリックしたままボタンをボタンの外にドラッグすると、
背景色は赤色になってほしいのですがマウスオーバー時の緑色になってしまいます。
ボタン外にカーソルがある(マウスオーバーしていない)のに
IsMouseOverがTrueになるのはなぜでしょうか。
どうすれば防ぐことができますか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/20 13:58