Bri*_*Low 5 wpf listbox togglebutton
我试图复制Word中的左/中/右对齐工具栏按钮.单击"左对齐"按钮时,取消选中"中心"和"右"按钮.我正在使用带有ToggleButtons的WPF ListBox.
问题是用户可以单击两次左对齐按钮.第二次单击会导致按钮取消选中并将基础值设置为null.我想第二次点击什么都不做.
想法?强制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>
Run Code Online (Sandbox Code Playgroud)