3 개의 버튼이 있습니다. MouseOver 및 Pressed 상태를 표시하는 세 개의 단추 모두에 대해 사용하는 스타일을 만들었습니다. 어떤 버튼이 선택/클릭되었는지를 나타내는 논리가 필요합니다. 버튼을 클릭하면 배경색은 눌려진 상태 그대로 유지되고 다른 두 개의 버튼은 배경색으로 재설정되어 정상 상태가됩니다. 아래 코드는 내가 가지고있는 코드이다. XAML에서 모두를 달성 할 수 있는지, 아니면 코드에서 어떻게 처리 할 수 있을지 궁금합니다. 내가 진심으로 감사한다.버튼을 클릭했을 때 버튼의 배경색을 변경하는 방법은 무엇입니까?
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="test3.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" SnapsToDevicePixels="true" Background="#FFFFE640">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="ButtonBackground">
<EasingColorKeyFrame KeyTime="0" Value="#FFC8B432"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="ButtonBackground">
<EasingColorKeyFrame KeyTime="0" Value="#FFBCAA31"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,0,0,4" HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Storyboard x:Key="OnMouseOneEnter">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_One">
<EasingColorKeyFrame KeyTime="0" Value="#FFDAC326"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnMouseOneLeave">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_One">
<EasingColorKeyFrame KeyTime="0" Value="#FFFFE640"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_Two">
<EasingColorKeyFrame KeyTime="0" Value="#FF85781C"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnMoseOneClick">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_One">
<EasingColorKeyFrame KeyTime="0:0:0.2" Value="#FFDAC326"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Grid>
<StackPanel x:Name="LayoutRoot">
<Button x:Name="button_One" HorizontalAlignment="Left" Width="90" Height="90" Content="One" Style="{DynamicResource ButtonStyle1}" Cursor="Hand" Margin="0,0,0,4" />
<Button x:Name="button_Two" HorizontalAlignment="Left" Width="90" Height="90" Content="Two" Style="{DynamicResource ButtonStyle1}" Cursor="Hand" Margin="0,0,0,4" />
<Button x:Name="button_Three" HorizontalAlignment="Left" Width="90" Height="90" Content="Two" Style="{DynamicResource ButtonStyle1}" Cursor="Hand" Margin="0,0,0,4" />
</StackPanel>
</Grid>
감사합니다. 나는 그것을 시도 할 것이다. – vladc77