2017-07-19 6 views
0

XAMLを使用してWPFリストボックスのすべてのアイテムを選択できますか?WPF ListBox select xamlのみを使用するすべてのアイテム

私もこの質問に続きWPF Listbox and Select Allに従っていますが、動作しません。 私のXAMLコードは次のように:

<ListBox SelectionMode="Multiple" Name="listBox"> 
    <ListBox.InputBindings> 
     <KeyBinding Command="ApplicationCommands.SelectAll" Modifiers="Ctrl" Key="A" /> 
    </ListBox.InputBindings> 
    <ListBox.CommandBindings> 
     <CommandBinding Command="ApplicationCommands.SelectAll" /> 
    </ListBox.CommandBindings> 
    <ListBoxItem>List Item 1</ListBoxItem> 
    <ListBoxItem>List Item 2</ListBoxItem> 
    <ListBoxItem>List Item 3</ListBoxItem> 
    <ListBoxItem>List Item 4</ListBoxItem> 
    <ListBoxItem>List Item 5</ListBoxItem> 
</ListBox> 

はXAMLによって選択可能なすべてのですか?

+0

* XAMLのみは、あなたが「コマンド」を使用しているためにあなたに意味するものは何ですか? –

+0

私はc#/ vbのコードビハインドコードがないことを意味します。私はコマンドバインディングを削除できます。 –

+0

私はpoweshellでこのXAMLビューを使用する必要があります。コードビハインドはそこでは機能しません。 –

答えて

1

いいえ、ListBoxには独自のSelectAllCommandがありますが、それはプライベートなのでバインドできません。あなたのためにApplicationCommands.SelectAllコマンドを処理しません。あなたはCommandBindingExecutedイベントを処理することにより、これを自分で行う必要があります。

private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) 
{ 
    listBox.SelectAll(); 
} 

XAMLは、マークアップ言語ではなく、プログラミング言語です。

関連する問題