【发布时间】:2009-09-17 22:19:29
【问题描述】:
我有一个使用 UserControl 作为项目模板的列表框。在 UserControl 内部,我有一个图像(一个 X),单击该图像时会发出事件以从列表框中删除 UserControl(listitem)。
当用户单击图像时,是否有办法防止列表框选择该项目,但仍允许为控件中的其他所有内容选择列表项?
【问题讨论】:
标签: c# wpf user-controls listbox wpf-controls
我有一个使用 UserControl 作为项目模板的列表框。在 UserControl 内部,我有一个图像(一个 X),单击该图像时会发出事件以从列表框中删除 UserControl(listitem)。
当用户单击图像时,是否有办法防止列表框选择该项目,但仍允许为控件中的其他所有内容选择列表项?
【问题讨论】:
标签: c# wpf user-controls listbox wpf-controls
确保在用户单击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;
}
【讨论】: