SL4 radiobutton数据绑定

时间:2011-09-07 09:43:18

标签: silverlight data-binding radio-button

我有两组独立的radiobuttons(在运行时填充)。我面临的问题是这两个群体表现为一个群体,即从一个群体中选择某个群体会取消选择另一个群体中的所选群体。

                    <ScrollViewer>
                        <ItemsControl ItemsSource="{Binding Path=AvailableX}" />
                    </ScrollViewer>
                    <ScrollViewer>
                        <ItemsControl ItemsSource="{Binding Path=AvailableY}" />
                    </ScrollViewer>


    public ObservableCollection<RadioButton> AvailableX
    {
        get
        {
            return _availableX;
        }
        set
        {
            _availableX = value;
        }
    }

    public ObservableCollection<RadioButton> AvailableY
    {
        get
        {
            return _availableY;
        }
        set
        {
            _availableY = value;
        }
    }

.....
.....

foreach (var x in _properties)
{
    AvailableX.Add(new RadioButton() { Content = x.ToString() });
    AvailableY.Add(new RadioButton() { Content = x.ToString() });
}

1 个答案:

答案 0 :(得分:4)

尝试设置群组名称:

new RadioButton() { Content = x.ToString(), GroupName = "X" });