首页 > 解决方案 > 操作子框架内的控件的最佳方法是什么?(UWP)

问题描述

我不确定在页面的子框架内操作控件的最佳方法是什么。看:

<Page x:Name="ParentPage">
    <!-- ParentPage contains a button. When the button is clicked I would like to select all the items in a ListView that is in the InnerPage Page. -->
    <Frame x:Name="SubFrame">
        <Page x:Name="InnerPage" />
    </Frame>
</Page>

现在 InnerPage 实际上是通过 C# 代码加载的,因为实际上有几个不同的 Pages 被加载到 SubFrame 框架中,因此很难像下面的示例那样做一些事情。但是,加载到子帧框架中的所有页面都包含完全相同的 ListView。

public sealed partial class ParentPage : Page
{
    public ParentPage()
    {
        InnerPage _InnerPage = SubFrame.Content as InnerPage;
        _InnerPage.SelectAllListViewItems();
    }
}

标签: c#xamluwp

解决方案


不太清楚为什么在 SubFrame 中使用具有相同 ListView 的不同内页以及要实现的实际效果。但是你可以尝试在你的项目中添加一些不同的页面,然后在页面的代码后面对页面进行操作,这样管理页面会更容易。

在父页面中,您可以使用Frame.Navigate 方法来加载您的子页面。

SubFrame.Navigate(typeof(ChildPage));

推荐阅读