我正在嘗試複製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