gpt4 book ai didi

windows-phone-7 - 如何检查列表的数据绑定(bind)何时完成? (WP7)

转载 作者:行者123 更新时间:2023-12-04 07:17:13 24 4
gpt4 key购买 nike

我有一个枢轴控件,其中它的项目包含一个带有项目的列表框。
当我滚动到下一个数据透视项时,数据绑定(bind)需要一些时间,我想知道数据绑定(bind)何时完成,因为我需要在列表框准备好出现时启用菜单栏。
我在这里找不到可以帮助我的事件。我尝试了列表框的 Loaded 事件,但是虽然它适用于某些枢轴项目,但对于其他一些它不会触发!
我也尝试了布局更新事件,但它被触发了太多次,它对我没有帮助。

我能做什么?
谢谢你

最佳答案

为确保快速滚动透视项目时的良好性能,您应该等待绑定(bind)透视项目的内容,直到 SelectedIndex 更改。这样,当用户在 Pivot 项目之间快速滑动时,它就不会尝试绑定(bind);它只会在您停在 Pivot 项目上时绑定(bind)。

然后,您应该在 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;
});
});

关于windows-phone-7 - 如何检查列表的数据绑定(bind)何时完成? (WP7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4709019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com