- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(WPF, ListBox);
&tag(WPF,ListBox);
*目次 [#tf14a3a6]
#contents
*参考情報 [#df059ced]
*Tips [#qe8a9a52]
**ユーザーの選択をキャンセルする [#s26bcf9f]
-[[mvvm - WPF: Cancel a user selection in a databound ListBox? - Stack Overflow:http://stackoverflow.com/questions/2608071/wpf-cancel-a-user-selection-in-a-databound-listbox]]
**ListBoxのなかにCheckBoxのリストを並べる [#u3d6c78a]
-[[wpf - What's the simplest way to bind a list of checkboxes to a list of checked values - Stack Overflow:http://stackoverflow.com/questions/782980/whats-the-simplest-way-to-bind-a-list-of-checkboxes-to-a-list-of-checked-values]]…ItemsPanelをカスタマイズする([[.net - Using StackPanel as ContentControl (WPF) - Stack Overflow:http://stackoverflow.com/questions/934873/using-stackpanel-as-contentcontrol-wpf]])。
**複数選択 [#k46f136c]
XAMLでSelectionMode="Multiple"を指定する。
#pre{{
<ListBox Grid.Row="1" Name="listBox" ItemsSource="{Binding Persons}" DisplayMemberPath="Name" SelectionMode="Multiple">
</ListBox>
}}
選択されたアイテムの取得方法。Bindingじゃなく、コードビハインドで取得するのが簡単か。
#pre{{
var items = listBox.SelectedItems;
foreach (object item in items)
{
Debug.WriteLine(item.ToString());
}
}}