我在XAML以下组合框元素:如何使用ObservableCollection源实现XAML单选按钮控件?
<ComboBox ItemsSource="{Binding CollectionControlValues}"
SelectedItem="{Binding CollectionControlSelectedValue, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我想实现单选按钮在同样的方式,像这样:
伪代码:
<RadioButtons ItemsSource="{Binding CollectionControlValues}"
SelectedItem="{Binding CollectionControlSelectedValue, UpdateSourceTrigger=PropertyChanged}">
<RadioButtons .ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}" />
</DataTemplate>
</RadioButtons .ItemTemplate>
</RadioButtons >
但是,唯一的WPF Rad我可以找到的ioButton实现是这样的static。
<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的例子吗?
你不需要来包装在?至少DataContext仍然引用父级的DataContext而不是项目类型。 请参阅:http://stackoverflow.com/q/1511516/134761 –
angularsen
2014-09-18 11:57:21
@angularsen正确! – 2017-10-13 08:22:24