首页 > 解决方案 > 如何在我选择它之前禁用 PivotItem 加载?(UWP C#)

问题描述

我需要使用 Pivot 但不加载所有 PivotItems 中的所有页面。只有当我选择这个特定的 PivotItem 时,才需要加载/重新加载 PivotItem 中的每个页面。

我已经尝试过,再见,Xaml 提供的所有功能,仅在 PivotItem 被按下但未成功时才执行操作。

<Pivot x:Name="XmlConfigPivot">
            <PivotItem Header="Layout">
                <Frame>
                    <xml_config:Layout_Tab/>
                </Frame>
            </PivotItem>
            <PivotItem Header="stub_tab">
                <Frame>
                    <xml_config:Stub_Tab/>
                </Frame>
            </PivotItem>
</Pivot>

仅当我选择它是 PivotItem 时,如何使“xml_config:Layout_Tab”加载?

标签: c#xamluwp

解决方案


As @Bruno said, you could directly load each page by programming. You just need to register the SelectionChanged event for the Pivot and add some code logic to achieve it.

The following is a simple code sample for your reference:

<Pivot x:Name="XmlConfigPivot" SelectionChanged="XmlConfigPivot_SelectionChanged">
        <PivotItem Header="Layout">
            <Frame>
            </Frame>
        </PivotItem>
        <PivotItem Header="stub_tab">
            <Frame>
            </Frame>
        </PivotItem>
</Pivot>
private void XmlConfigPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    PivotItem item = ((sender as Pivot).SelectedItem) as PivotItem;
    string header = item.Header.ToString();
    Frame frame = item.Content as Frame;
    switch (header)
    {
            case "Layout": frame?.Navigate(typeof(page1)); break;
            case "stub_tab": frame?.Navigate(typeof(page2)); break;
    }
}

推荐阅读