枢轴控件上的 LoadedPivotItem 事件未首次触发,WP7

发布于 2024-12-29 11:16:25 字数 638 浏览 1 评论 0原文

当分配数据透视表的 DataContext 从而创建数据透视表项时,是否有任何原因不会触发事件 LoadedPivotItem?

仅当我切换到已由 _SelectionChanged 事件处理的下一个枢轴项目时,才会触发它。

 protected override void OnNavigatedTo
    (System.Windows.Navigation.NavigationEventArgs e)
    {
        var someData = LoadData();

        pivot.DataContext = someData;
        base.OnNavigatedTo(e);
    }

 void pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
    {
        // Will not stop here after data being assigned to DataContext
    }

我特别需要此事件,因为我需要 PivotItem 及其数据上下文以进行进一步操作。 我是否做错了什么,或者在获取 PivotItem ( PivotItemEventArgs ) 时我可以在此处使用其他一些事件。

谢谢

is there any reason why event LoadedPivotItem is not fired when DataContext of Pivot is being assigned therefore creating Pivot Items ?

It is only fired when I swype to next pivot item which is already handled by _SelectionChanged event.

 protected override void OnNavigatedTo
    (System.Windows.Navigation.NavigationEventArgs e)
    {
        var someData = LoadData();

        pivot.DataContext = someData;
        base.OnNavigatedTo(e);
    }

 void pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
    {
        // Will not stop here after data being assigned to DataContext
    }

I need this event in particular cause I need PivotItem and it's data context for further operations.
Is there something I am doing wrong, or is there some other event that I can use here while getting a PivotItem ( PivotItemEventArgs ).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2025-01-05 11:16:25

我认为问题在于页面加载的时间。我没有看到您在代码中附加事件处理程序,因此我假设您在 XAML 中指定事件处理程序。在页面上的所有内容完全加载并连接之前,该事件可能触发得太早。

尝试从 XAML 中删除事件处理程序并将其移至 OnNavigedTo 事件(伪代码):

protected override void OnNavigatedTo (NavigationEventArgs e)
{
    var someData = LoadData();

    pivot.DataContext = someData;
    OnLoadedPivotItem += pivot_LoadedPivotItem;
    base.OnNavigatedTo(e);
}

如果这不起作用,这篇文章可能会有所帮助。它描述了加载控制树时发生的事件序列。跳出的潜在有用的建议是附加到 LayoutUpdated 事件而不是 Loaded 事件。

I think the problem is the timing of how your page is loading. I don't see you attaching an event handler in your code, so I'm assuming that you're specifying the event handler in your XAML. The event may be firing too early, before everything on your page is fully loaded and wired up.

Try removing the event handler from your XAML and moving it to your OnNavigatedTo event (pseudocode):

protected override void OnNavigatedTo (NavigationEventArgs e)
{
    var someData = LoadData();

    pivot.DataContext = someData;
    OnLoadedPivotItem += pivot_LoadedPivotItem;
    base.OnNavigatedTo(e);
}

If that doesn't work, this article might be helpful. It describes the sequence of events that happens as the control tree is loaded. The suggestion that jumped out as potentially useful was attaching to the LayoutUpdated event instead of the Loaded event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文