我有一个枢轴控件,其项目包含一个包含项目的列表框。
当我滚动到下一个数据透视项时,数据绑定需要一些时间,我想知道数据绑定何时完成,因为我需要在列表框准备好出现后立即启用菜单栏。
我在这里找不到可以帮助我的活动。我尝试了列表框的 Loaded 事件,但虽然它适用于某些枢轴项目,但对于其他一些项目,它不会触发!
我还尝试了布局更新事件,但它被触发了太多次,它对我没有帮助。
我能做什么?
谢谢
为了确保在快速滚动数据透视项时获得良好的性能,您应该等到 SelectedIndex 更改后才绑定数据透视项的内容。这样,当用户在 Pivot 项目之间快速滑动时,它就不会尝试绑定;仅当您停在枢轴项目上时它才会绑定。
然后,您应该在 LayoutUpdated 事件中设置 Pivot 项中 ListBox 的 ItemsSource 属性。我使用以下扩展方法:
public static void InvokeOnLayoutUpdated(this FrameworkElement element, Action action)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
else if (action == null)
{
throw new ArgumentNullException("action");
}
// Create an event handler that unhooks itself before calling the
// action and then attach it to the LayoutUpdated event.
EventHandler handler = null;
handler = (s, e) =>
{
element.LayoutUpdated -= handler;
action();
};
element.LayoutUpdated += handler;
}
所以你会得到一些看起来像这样的代码:
pivot.InvokeOnLayoutUpdate(() =>
{
Dispatcher.BeginInvoke(() =>
{
list.ItemsSource = source;
ApplicationBar.IsMenuEnabled = true;
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)