如何仅突出显示4个按钮中的一个按钮

时间:2016-09-02 02:49:43

标签: wpf xaml

屏幕上有4个按钮。当我单击一个按钮时,我在同一个UI上加载网格数据。

当我点击第二个按钮时,我只是清除旧数据并绑定相应网格的新数据。

我只想在点击它时只突出显示一个按钮。

我正在使用MVVM模式,所以..只需要在XAML中解决这个问题。

示例:

我点击了第一个按钮,它将根据选择在网格上加载数据。 现在按钮1应该突出显示。

当我点击第二个按钮时。按钮1应处于正常状态,第二个按钮应突出显示。

在我们进入视图之前,只有一个按钮突出显示应处于突出显示模式。

2 个答案:

答案 0 :(得分:0)

您应该使用WPF触发器。在你的情况下,它是 IsPressed 。简单的例子:

<Trigger Property="IsPressed" Value="True">
        <Setter Property="Background" Value="Red"/>
        <Setter Property="BorderBrush" Value="1"/>
    </Trigger>

这是一个适合我的完整示例

 <Window.Resources>
    <Style x:Key = "TriggerStyle" TargetType="{x:Type Button}">
        <Style.Triggers>
            <Trigger Property = "IsPressed" Value = "True">
                <Setter Property = "Background" Value = "Red" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid>

    <Button x:Name="button" Style = "{StaticResource TriggerStyle}" Content="Button" HorizontalAlignment="Left" Margin="103,45,0,0" VerticalAlignment="Top" Width="75"/>
    <Button x:Name="button1" Style = "{StaticResource TriggerStyle}" Content="Button" HorizontalAlignment="Left" Margin="163,130,0,0" VerticalAlignment="Top" Width="75"/>

</Grid>

如果它仍然无效,那么也许你应该发布你的xaml。

答案 1 :(得分:-1)

我认为您正在寻找clickNext(":jh"); s。

RadioButton