現状・実現したいこと
ボタンをクリックして、ボタンを離れた時の色をはじめの状態に戻したいです。
ボタンの色に関して該当のソースコードは、下記の状態となります。
・はじめの状態:白
・マウスオーバー時:緑色
・クリック時:赤色
・クリックした後にボタンを離れる:白
問題は、キーボードフォーカスの色を指定した場合です。
キーボードフォーカス状態のトリガーを設定すると(該当ソースコードではコメントアウトを解除して下さい)、
クリックした時にボタンの色は黄色になり、
一度クリックすると、マウスがボタンを離れてもそのまま黄色の状態となってしまいます。
これを下記の状態にすることは可能でしょうか?
・はじめの状態:白
・マウスオーバー時:緑色
・クリック時:赤色
・クリックした後にボタンを離れる:白
・キーボードフォーカス時:黄色
以上よろしくお願いいたします。
該当のソースコード
<Window x:Class="Button01.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:Button01" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ControlTemplate x:Key="buttonTest" TargetType="Button"> <Border Name="border" BorderThickness="1" BorderBrush="DarkGray" CornerRadius="5" TextBlock.Foreground="Black"> <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <!--マウスオーバー時--> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="Green" /> </Trigger> <!--クリック時--> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="Red" /> </Trigger> <!--キーボード フォーカス状態--> <!--<Trigger Property="IsKeyboardFocused" Value="true"> <Setter TargetName="border" Property="Background" Value="Yellow" /> </Trigger>--> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources> <Grid> <Button Content="Button" Template="{StaticResource buttonTest}" HorizontalAlignment="Left" Margin="226,145,0,0" VerticalAlignment="Top" Width="75" /> <TextBox HorizontalAlignment="Left" Height="23" Margin="200,211,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" /> </Grid> </Window>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/28 00:22
2018/05/28 01:22
2018/05/28 01:52