【问题标题】:XamlReader.Parse and RadioButton GroupNameXamlReader.Parse 和 RadioButton GroupName
【发布时间】:2012-06-27 15:05:40
【问题描述】:

我有一个很奇怪的问题。有没有可能让这两个控件radionewRadio 具有属性IsChecked == true。在执行第 6 行代码之前radio.IsChecked == true,但在执行第 6 行代码之后radio.IsChecked == falsenewRadio.IsChecked == true

这两个单选按钮是否有可能具有IsChecked == true 和相同的GroupName

1. RadioButton radio = new RadioButton();       

2. radio.GroupName = "group";
3. radio.IsChecked = true;          
4. radio.Name = "name";         

5. string xaml = XamlWriter.Save(radio);

6. var newRadio = XamlReader.Parse(xaml);

【问题讨论】:

    标签: wpf xaml radio-button xamlreader


    【解决方案1】:

    GroupName -> "获取或设置指定哪些 RadioButton 控件互斥的名称。"

    所以通常不会,如果多个单选按钮共享同一个组代码,一次只应检查一个。

    作为一种技巧,您可以更改第一个单选按钮的组名,创建第二个,然后将其放回原处。您应该检查两个单选按钮,但我不建议这样做。

    例子:

    radio.GroupName = String.Empty;
    var newRadio = XamlReader.Parse(xaml);
    radio.GroupName = "group";
    

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2014-06-03
      相关资源
      最近更新 更多