拖动Item
选择已经选中的Item
选择一个已经选中的 item :有时,需要处理选择一个已经选中的 item,可是这时 SelectionChanged 不会被再次触发。一个解决方法是,用 EventSetter 将 item 的事件代理出去。
<
ListBox
SelectionChanged
="ListBox_SelectionChanged"
>
< ListBox.ItemContainerStyle >
< Style TargetType ="ListBoxItem" >
< EventSetter Event ="PreviewMouseLeftButtonDown" Handler ="ListBox_MouseLeftButtonDown" />
</ Style >
</ ListBox.ItemContainerStyle >
< TextBlock Text ="qwer" />
< TextBlock Text ="asdf" />
< TextBlock Text ="zxcc" />
</ ListBox >
< ListBox.ItemContainerStyle >
< Style TargetType ="ListBoxItem" >
< EventSetter Event ="PreviewMouseLeftButtonDown" Handler ="ListBox_MouseLeftButtonDown" />
</ Style >
</ ListBox.ItemContainerStyle >
< TextBlock Text ="qwer" />
< TextBlock Text ="asdf" />
< TextBlock Text ="zxcc" />
</ ListBox >
参考:
改变选中项目的背景色
<!--
change background of selected item
-->
< ListBox >
< ListBox.Style >
< Style >
< Style.Resources >
< SolidColorBrush x:Key =" {x:Static SystemColors.HighlightBrushKey} " Color ="Red" />
< SolidColorBrush x:Key =" {x:Static SystemColors.ControlBrushKey} " Color ="Green" />
</ Style.Resources >
</ Style >
</ ListBox.Style >
< TextBlock Text ="customized background color" />
</ ListBox >
< ListBox >
< ListBox.Style >
< Style >
< Style.Resources >
< SolidColorBrush x:Key =" {x:Static SystemColors.HighlightBrushKey} " Color ="Red" />
< SolidColorBrush x:Key =" {x:Static SystemColors.ControlBrushKey} " Color ="Green" />
</ Style.Resources >
</ Style >
</ ListBox.Style >
< TextBlock Text ="customized background color" />
</ ListBox >
to be continued ...