首页 > Windows开发 > 详细

WPF Tips: Listbox SelectionChanged触发前的选项

时间:2016-03-30 19:39:06      阅读:738      评论:0      收藏:0      [点我收藏+]

想在Listbox的SelectionChanged事件触发时对之前的选项进行处理。但是listbox没有previewSelectionChanged事件。

解决办法:

1. Validation

因为要处理的项在TextBox中,所以可以给TextBox添加一个Validation。但是由于TextBox是与Property Binding,而Validation是在binding赋值之前进行操作(调试过程中是这样的流程),所以无法获取textbox中的值。如果没有binding应该是可以。

参考:https://social.msdn.microsoft.com/Forums/vstudio/en-US/e96c725e-a86d-427e-944b-fcc4273ac260/any-way-to-preview-the-listviewselectionchanged-event?forum=wpf

2. 获取SelectionChangedEventArgs中的RemovedItem。最后采用的这个方法。

private void ListBox_SelectionChanged(object sender , SelectionChangedEventArgs e)
{
    // Here are your old selected items from the selection changed.
    // If your list box does not allow multiple selection, then just use the index 0
    // but making sure that the e.RemovedItems.Count is > 0 if you are planning to address by index.
    IList oldItems = e.RemovedItems;

    // Do something here.

    // Here are you newly selected items.
    IList newItems = e.AddedItems;
}

参考:http://stackoverflow.com/questions/1548237/how-to-get-something-like-previewselectionchanged-event-in-listbox

WPF Tips: Listbox SelectionChanged触发前的选项

原文:http://www.cnblogs.com/jane850113/p/5338218.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!