gpt4 book ai didi

c# - WPF 中的切换按钮

转载 作者:行者123 更新时间:2023-11-30 14:55:43 24 4
gpt4 key购买 nike

我有两个 ToggleButtons。我只希望其中一个在任何时候都处于 Pressed 状态。假设 Model ToggleButton 被按下:

我想实现以下概念:

  1. 如果我按下 Drawing ToggleButtonModel ToggleButton 将被取消按下并且 Drawing ToggleButton 将进入按下状态。
  2. 如果按下处于按下状态的 Model Button,则不会发生任何事情。

顺便说一句,这是我到目前为止所做的一切:(

<ToggleButton Width="50" Height="23"  Margin="0 0 0 0">Model</ToggleButton>
<ToggleButton Width="50" Height="23" Margin="0 0 7 0">Drawing</ToggleButton>

更新:

使用评论下提供的链接,我想到了这个:

<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Content="Model" IsChecked="True" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Content="Drawing" />

现在上面的代码给了我两个按钮,但我该如何设置它们的样式呢?我知道如何设计风格。但我不知道在这里要做什么风格?我的意思是,我已经在此处填充了样式属性,如何设置 ToggleButton 本身的样式?

enter image description here

最佳答案

由于RadioButton 继承自ToggleButton,您可以为其设置ToggleButton 样式并使用BasedOn 继承ToggleButton 的默认样式 像这样:

<RadioButton GroupName="Test" Width="50" Height="23" Margin="0 0 7 0"
Content="Model">
<RadioButton.Style>
<Style TargetType="ToggleButton"
BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Background" Value="Red"/>
<!-- Set other properties here-->
</Style>
</RadioButton.Style>
</RadioButton>

关于c# - WPF 中的切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com