Wpf itemscontrol中的互斥按钮
我将按钮作为itemscontrol的项。可以选中该按钮,使其在单击后显示为高亮显示,直到再次单击为止(具有ischecked属性)。我的问题是我需要使这个按钮检查相互排斥?在任何时候,我只希望有一个按钮高亮显示。我使用itemscontrol是因为我可以包装按钮,使其水平填充到分配的宽度,并继续到下一行 下面的XAMLWpf itemscontrol中的互斥按钮,wpf,Wpf,我将按钮作为itemscontrol的项。可以选中该按钮,使其在单击后显示为高亮显示,直到再次单击为止(具有ischecked属性)。我的问题是我需要使这个按钮检查相互排斥?在任何时候,我只希望有一个按钮高亮显示。我使用itemscontrol是因为我可以包装按钮,使其水平填充到分配的宽度,并继续到下一行 下面的XAML <ItemsControl ItemsSource="{Binding Path=NewItemsList,ElementName=newitemcontrol}">
<ItemsControl ItemsSource="{Binding Path=NewItemsList,ElementName=newitemcontrol}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" >
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<dc:ButtonDropDown Name="SubItems" Width="120"
Height="120" ItemsSource="{Binding Path=DataContext.Children, RelativeSource={RelativeSource Mode=Self}}" Header="{Binding Path=DataContext.DisplayName, RelativeSource={RelativeSource Mode=Self}}" Command="{Binding Path=ChangeSubItem, ElementName=newitemcontrol}" CommandParameter="{Binding DataContext, RelativeSource={RelativeSource Mode=Self}}" ImageSource="{Binding Path=DataContext.ImageUri, RelativeSource={RelativeSource Mode=Self}}" ImagePosition="Top" IsCheckable="True" >
</dc:ButtonDropDown>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
谢谢您的回复。我需要在容器中使用dropdownbutton(我知道radiobutton)。我解决这个问题的方法是使用listbox而不是itemscontrol。listbox应该是单选的,并将dropdownbutton ischecked属性绑定到其listboxitem的isselected属性。您可以使用GroupName属性使用RadioButton来实现这一点。我不知道dc:buttondropdown还有,如果项目是静态元素,您可能需要使用面板
(而不是ItemsControl
)