我已经使用ff连接到了ListBoxItems的双击事件。我的XAML中的代码:
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseDoubleClick" Handler="onMouseDoubleClickOnListBoxItem" />
</Style>处理程序的代码是:
private void onMouseDoubleClickOnListBoxItem(object sender, MouseButtonEventArgs e)
{
Debug.Print("Going to select all.");
listBox.SelectAll();
Debug.Print("Selected all.");
}当我运行它时,我看到了调试输出,但并不是所有的项都在屏幕上被选中。
发布于 2010-10-19 11:07:59
尝试将SelectionMode作为多个。
更新,
在扩展模式中,执行双击的项被重置为SelectedItem,这是因为在同一线程上执行选择单个项的单击事件操作。
为了实现这一点,did在双击事件处理程序上调用(begin invoke -这是异步的)一个委托方法(在类范围内),并从那里调用主窗口调度程序上的列表框的SelectAll调用。
喜欢,
// delegate
delegate void ChangeViewStateDelegate ();
// on double click event invoke the custom method
private void onMouseDoubleClickOnListBoxItem (object sender, MouseButtonEventArgs e) {
ChangeViewStateDelegate handler = new ChangeViewStateDelegate (Update);
handler.BeginInvoke (null, null);
}
// in the custom method invoke the selectall function on the main window (UI which created the listbox) thread
private void Update () {
ChangeViewStateDelegate handler = new ChangeViewStateDelegate (UIUpdate);
this.Dispatcher.BeginInvoke (handler, null);
}
// call listbox.SelectAll
private void UIUpdate () {
lstBox.SelectAll ();
}https://stackoverflow.com/questions/3964902
复制相似问题