【问题标题】:Sending LoadingPivotItem event to PivotItems (UserControls)将 LoadingPivotItem 事件发送到 PivotItems (UserControls)
【发布时间】:2013-09-20 02:09:41
【问题描述】:

所以,我将 Pivot 和 PivotItems 作为 UserControls。 我想知道,每个 PivotItem 何时是 NavigatedTo 和 NavigatedFrom。

我创建了一个基类(PivotItems 继承了它),添加了 2 个方法(To 和 From),并且我在枢轴中有 LoadingPivotItemCommand(),所以我知道加载了哪个 PivotItem。

但是如何将此事件广播到枢轴?我尝试了一些方法,但都是空值。

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 中定义:

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

【问题讨论】:

  • 请编辑标题,使其更具描述性。
  • @anderZubi 添加。你是对的:我想,这个更好。对这个问题有什么建议吗?
  • 我真的不明白你在做什么?您不能使用 Pivot 项的 SelectionChanged 事件来实现您的目标吗?
  • @anderZubi 是的,我可以在 Pivot 中捕捉事件。我还想通知 PivotItem,它应该加载或卸载数据。
  • @anderZubi 实际上,问题是将 args.Item 转换为 BaseUserControl

标签: xaml windows-phone-7 navigation


【解决方案1】:

我猜 ProductUserControl 是继承形式 BaseUserControl 的一个。如果您的 BaseUserControl 始终在您显示的 xaml 中的 Grid 内,那么您可以使用:

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

否则,如果您的 UserControl 可以放置在 PivotItem 内的不同部分,那么您可以使用 I gave you 的功能,只需将 Image 替换为 BaseUserControl。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    相关资源
    最近更新 更多