【问题标题】:RadioButton is not Checked when Checked property is set to true当 Checked 属性设置为 true 时,未选中 RadioButton
【发布时间】:2018-09-11 04:08:15
【问题描述】:

当 checked 属性为 true 时,单选按钮不会在 UWP 中被选中。单选按钮不在组中。请参阅下面的代码。

        <StackPanel Orientation="Horizontal">
        <RadioButton Content="1" IsChecked="True"/>
        <RadioButton IsChecked="True"/>
        </StackPanel>

您只能看到第二个单选按钮被选中。为什么?

【问题讨论】:

  • 为他们创建单独的组。

标签: c# xamarin uwp


【解决方案1】:

因为您通过将它们放入同一个容器中来对它们进行分组。 来自 UWP Radio Button documentation

单选按钮成组工作。有两种方法可以对单选按钮控件进行分组:

  • 将它们放在同一个父容器中。
  • 将每个单选按钮的 GroupName 属性设置为相同的值。

【讨论】:

  • 如果我为两个单选按钮和 isChecked= true 的组名属性指定相同的名称,那么这两个单选按钮都会被选中。
【解决方案2】:

RadioButton 的目的是当 RadioButton 组合在一起时,一次只会选择单个项目。 如果你想一次多选,你可以在 RadioButton 上使用 CheckBox。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    相关资源
    最近更新 更多