このトピックを検索し、いくつかのディスカッションが見つかりました。 私はこれらの実装について気に入らなかったのは、特別な種類のバインドされたデータ(IsSelectedプロパティ)を暗示しているか、通常のキーボードサポートが不足していたことです。XAMLの "CheckListBox"内のすべてのCheckBoxを選択/選択解除する
リストのCheckBoxは、機能的な拡張ではなく装飾的なものであるため、それに応じて処理する必要があります。
私はこの素敵で親切記事から始まっ:http://www.gbogea.com/2010/01/02/mvvm-multiselect-listbox
しかし、私はViewModelにの賛成でビューをハッキング信じかなり良い習慣ではありません。それはViewModelをViewとModelに適応させるものです。確かに、IMHO。
だから私は少し変更して、このXAMLを終え:
<ListBox Name="checkboxList"
ItemsSource="{Binding Sports}"
Margin="0,5"
SelectionMode="Multiple">
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="ListBoxItem.Background" Value="Transparent"/>
<Setter Property="ListBoxItem.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd"
SnapsToDevicePixels="true"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected, Mode=TwoWay}"
Content="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ここでチェックボックスの選択がListBoxItem.IsSelectedやリストボックスと同期しているがバインドされたデータの特殊性を認識していません。
これはOKです。 しかし、コントロールテンプレートにもう1つのチェックボックスを追加することで、リストボックスのすべての選択/選択解除を追加する方法はありますか? XAMLのみを使用する。
質問は? – vulkanino
えー..質問を忘れた=)申し訳ありません。 –