首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >双击时选择所有ListBoxItems

双击时选择所有ListBoxItems
EN

Stack Overflow用户
提问于 2010-10-19 10:20:51
回答 1查看 239关注 0票数 0

我已经使用ff连接到了ListBoxItems的双击事件。我的XAML中的代码:

代码语言:javascript
复制
    <Style TargetType="{x:Type ListBoxItem}">
        <EventSetter Event="MouseDoubleClick" Handler="onMouseDoubleClickOnListBoxItem" />
    </Style>

处理程序的代码是:

代码语言:javascript
复制
    private void onMouseDoubleClickOnListBoxItem(object sender, MouseButtonEventArgs e)
    {
        Debug.Print("Going to select all.");
        listBox.SelectAll();
        Debug.Print("Selected all.");
    }

当我运行它时,我看到了调试输出,但并不是所有的项都在屏幕上被选中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-19 11:07:59

尝试将SelectionMode作为多个。

更新,

在扩展模式中,执行双击的项被重置为SelectedItem,这是因为在同一线程上执行选择单个项的单击事件操作。

为了实现这一点,did在双击事件处理程序上调用(begin invoke -这是异步的)一个委托方法(在类范围内),并从那里调用主窗口调度程序上的列表框的SelectAll调用。

喜欢,

代码语言:javascript
复制
// 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 ();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3964902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档