我在XAML中有以下ComboBox元素:
我想以“同样的方式”实现 RadioButtons,如下所示:
然而,我能找到的唯一的 WPF RadioButton 实现都是像这样的 静态 实现。
如何创建一个单选按钮控件,它不像上面的静态控件那样,而是从其ItemsSource属性中获取数据,就像上面ComboBox的例子一样?
<ComboBox ItemsSource="{Binding CollectionControlValues}"
SelectedItem="{Binding CollectionControlSelectedValue, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我想以“同样的方式”实现 RadioButtons,如下所示:
伪代码:
<RadioButtons ItemsSource="{Binding CollectionControlValues}"
SelectedItem="{Binding CollectionControlSelectedValue, UpdateSourceTrigger=PropertyChanged}">
<RadioButtons .ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}" />
</DataTemplate>
</RadioButtons .ItemTemplate>
</RadioButtons >
然而,我能找到的唯一的 WPF RadioButton 实现都是像这样的 静态 实现。
<StackPanel x:Name="rbHolder1" Style="{StaticResource rbStackPanelStyle}">
<RadioButton Style="{StaticResource rbStyle}">RadioButton 1</RadioButton>
<RadioButton Style="{StaticResource rbStyle}">RadioButton 2</RadioButton>
<RadioButton Style="{StaticResource rbStyle}">RadioButton 3</RadioButton>
<RadioButton Style="{StaticResource rbStyle}">...</RadioButton>
</StackPanel>
如何创建一个单选按钮控件,它不像上面的静态控件那样,而是从其ItemsSource属性中获取数据,就像上面ComboBox的例子一样?