【问题标题】:Listbox with Custom Listitem -- Prevent Selection?带有自定义列表项的列表框 - 防止选择?
【发布时间】:2009-09-17 22:19:29
【问题描述】:

我有一个使用 UserControl 作为项目模板的列表框。在 UserControl 内部,我有一个图像(一个 X),单击该图像时会发出事件以从列表框中删除 UserControl(listitem)。

当用户单击图像时,是否有办法防止列表框选择该项目,但仍允许为控件中的其他所有内容选择列表项?

【问题讨论】:

    标签: c# wpf user-controls listbox wpf-controls


    【解决方案1】:

    确保在用户单击Image 时将事件标记为已处理:

    private void ImageClicked(object sender, RoutedEventArgs e)
    {
        //send out event to remove UserControl
    
        //ensure the event doesn't bubble up further to the ListBoxItem
        e.Handled = true;
    }
    

    【讨论】:

    • 我愿意,但我处理“点击”OnMouseButtonUp,显然列表框处理选择 OnMouseButtonDown。我尝试过使用 HitTest 框架,但到目前为止没有运气。
    • 处理了 MouseLeftButtonDown 事件并修复了!我觉得现在问很傻=)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多