如何将 WinUi 3 RadioButtons 设置为一组切换按钮?

问题描述 投票:0回答:1

我需要将一些分组单选按钮设置为切换按钮,如下所示,如何在 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> 
c# radio-button winui-3 togglebutton
1个回答
0
投票

这应该有效:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.