本文介绍了将LoadingPivotItem事件发送到PivotItems(UserControls)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将Pivot和PivotItems用作UserControls.我想知道何时每个PivotItem都是NavigatedTo和NavigatedFrom.

So, i have Pivot and PivotItems as UserControls. I'd like to know, when every PivotItem is NavigatedTo and NavigatedFrom.

我做了一个基类(PivotItems继承了它),在其中添加了2个方法(To和From),并且在数据透视中有LoadingPivotItemCommand(),所以我知道要加载哪个PivotItem.

I made a base class (PivotItems are inheriting it), added there 2 methods (To and From), and i have LoadingPivotItemCommand() in the pivot, so i know, which PivotItem is loaded.

但是如何将该事件广播到枢轴?我尝试了一些方法,但所有方法都为空.

But how to broadcast this event to pivots? I tried some ways, but all of them are nulls.

void LoadingPivotItemCommand(PivotItemEventArgs args)
    {
        var b = args.Item.Parent as BaseUserControl;
        var a = args.Item.Content as BaseUserControl;
        var a1 = args.Item.Content as UserControl;

        var c = args.Item.DataContext as BaseUserControl;

        if (c != null) 
            c.OnPivotItemActivated();
    }

PivotItems在xaml中定义:

PivotItems are defined in xaml:

   <controls:PivotItem Header="{Binding Path=MainResources.Products, Source={StaticResource LocalizedStrings}, Converter={StaticResource StringToLowerCaseConverter}}"
                            Name="PivotItemProducts">
            <Grid>
                <productsView:ProductUserControl />     
            </Grid>
        </controls:PivotItem>

推荐答案

我猜ProductUserControl是一种继承自BaseUserControl的形式.如果您的BaseUserControl总是像您显示的xaml一样位于Grid内,则可以使用:

I'm guessing ProductUserControl is the one inheriting form BaseUserControl. If your BaseUserControl is always inside a Grid like in the xaml you show then you could just use :

var a1 = (args.Item.Content as Grid).Children[0] as BaseUserControl;

否则,如果您的UserControl可以放置在PivotItem内部的不同部分,则可以使用,只是用BaseUserControl替换了Image.

Otherwise if your UserControl can be place at different part inside the PivotItem then you can just use the function that I gave you, just replacing Image by BaseUserControl.

这篇关于将LoadingPivotItem事件发送到PivotItems(UserControls)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:08