我正在尝试复制Word中的左/中/右对齐工具栏按钮。当您单击“左对齐”按钮时,取消选中“中心”和“右”按钮。我正在使用带有ToggleButtons的WPF ListBox。ToggleButton组:确保在列表框中始终选择一个项目
问题是用户可以单击左对齐按钮两次。第二次点击会导致按钮取消选中并将基础值设置为空。我想第二次点击什么也不做。
想法?强制ListBox始终有一个选定的项目?阻止视图模型中的null(需要刷新ToggleButton绑定)?
<ListBox ItemsSource="{x:Static domain:FieldAlignment.All}" SelectedValue="{Binding Focused.FieldAlignment}">
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}">
<TextBlock Text="{Binding Description}" />
</ToggleButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
谢谢。在OnClick事件中:if(toggleButton.IsChecked == false)toggleButton.IsChecked = true; – 2010-08-01 23:25:45
err其实我正在考虑更多关于这个 ToggleButton> –
dnr3
2010-08-02 08:12:58