我现在正面临着一个奇怪的问题。
我已经创建了一个基于WPF页面导航的WPF应用程序。我有几个按钮,根据按钮的点击,用户被导航到各自的WPF页面。
在这些WPF页面中,我有Tab控件,并使用selectionchanged事件处理程序来执行一些任务。
现在来看问题,
当我试图转到一个特定的页面时,selectionchanged事件也会被执行,甚至在页面完全加载之前,我已经尝试使用windows.loaded (基于对上一个问题的回答-- here) --我没有运气。
我正在使用WPF导航框架
不知怎么的,selectionchanged事件执行了两次。
我如何阻止这种情况的发生?
发布于 2012-12-22 17:52:50
我认为你应该检查一下SelectionChange.AddedItems和SelectionChange.RemovedItems来找出它们之间的区别。我猜当你选择一个页面时,SelectionChange.RemovedItems==0,而当你点击一个tabItem来选择它时,SelectionChange.RemovedItems==1。如果是这样,只需写:
if (SelectionChange.RemovedItems==0)
return;Edit1:请参阅第一条评论。
编辑2
void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count == 0)
{
// I guess this is the event that happens when a page is selected
// in this case just a TabItem is added to the selection
// and nothing is removed, so do nothing
return;
}
// if you are here, it means that this is another selection changed event
// so Perform those tasks that you mentioned in your question
}https://stackoverflow.com/questions/14001739
复制相似问题