我需要将一些分组单选按钮设置为切换按钮,如下所示,如何在 WinUi 中实现此功能
这是在 WPF 中执行相同操作的问题。 将 WPF 单选按钮设置为具有正确 IsEnabled 行为的切换按钮
<StackPanel >
<RadioButtons Header="Options:" MaxColumns="3">
<RadioButton Content="Option 1" Checked="RadioButton_Checked" AutomationProperties.AutomationId="Option1RadioButton"/>
<RadioButton Content="Option 2" Checked="RadioButton_Checked" AutomationProperties.AutomationId="Option2RadioButton"/>
<RadioButton Content="Option 3" Checked="RadioButton_Checked" AutomationProperties.AutomationId="Option3RadioButton"/>
</RadioButtons>
</StackPanel>
这应该有效:
<RadioButtons>
<RadioButtons.Resources>
<Style TargetType="RadioButton">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<ToggleButton
Content="{x:Bind Content, Mode=OneWay}"
IsChecked="{x:Bind IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</RadioButtons.Resources>
<RadioButton
AutomationProperties.AutomationId="Option1RadioButton"
Checked="RadioButton_Checked"
Content="Option 1" />
<RadioButton
AutomationProperties.AutomationId="Option2RadioButton"
Checked="RadioButton_Checked"
Content="Option 2" />
<RadioButton
AutomationProperties.AutomationId="Option3RadioButton"
Checked="RadioButton_Checked"
Content="Option 3" />
</RadioButtons>