在VS C#Windows Universal中切换页面中心类的不同方法

在VS C#Windows Universal中切换页面中心类的不同方法,c#,navigation,controls,win-universal-app,windows-10-universal,C#,Navigation,Controls,Win Universal App,Windows 10 Universal,因此,这似乎很基本,但到目前为止,我在C#中找到的在windows universal app中切换当前页面的唯一方法是使用标题单击方法,并将IsHeaderInteractive设置为true。这看起来或感觉都不是很直观,因为它只是停留在你点击的“查看更多”按钮上。相反,我将如何向整个中心部分添加一个单击事件来更改页面。这是我现在拥有的 private void HubSection_Click(object sender, HubSectionHeaderClickEven

因此,这似乎很基本,但到目前为止,我在C#中找到的在windows universal app中切换当前页面的唯一方法是使用标题单击方法,并将IsHeaderInteractive设置为true。这看起来或感觉都不是很直观,因为它只是停留在你点击的“查看更多”按钮上。相反,我将如何向整个中心部分添加一个单击事件来更改页面。这是我现在拥有的

         private void HubSection_Click(object sender, HubSectionHeaderClickEventArgs e)
    {

        switch (e.Section.Name)
        {
            case "China":
                Frame.Navigate(typeof(SubtopicPage));
                break;
            case "Japan":
                Frame.Navigate(typeof(SubtopicPage));
                break;
        }

    }
以下是XAML:

  <Page
x:Class="TestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource SystemControlForegroundBaseHighBrush}">
    <Hub Header="Countries App" Foreground="#FFC3BFBF" SectionHeaderClick="HubSection_Click" Name="CountryHub">
        <HubSection x:Name="China" MinWidth="256" Height="460" Background="#FF343434" Header="China" IsHeaderInteractive="True">
            <DataTemplate>
                <Grid Height="460" Width="256" VerticalAlignment="Bottom">
                    <Image Source="Assets/chinaFlag.bmp"/>
                </Grid>
            </DataTemplate>
        </HubSection>

        <HubSection x:Name ="Japan" MinWidth="256" Height="460" Background="#FF565454" Header="Japan" IsHeaderInteractive="True">
            <DataTemplate>
                <Grid Height="460" Width="256" VerticalAlignment="Bottom">
                    <Image Source="Assets/japanFlag.bmp" Height="169"/>
                </Grid>
            </DataTemplate>
        </HubSection>
        <HubSection Width="256" Height="460" Background="#FF343434">

        </HubSection>
        <HubSection Width="256" Height="460" Background="#FF565454">
            <DataTemplate>
                <Grid Height="460" Width="256" VerticalAlignment="Bottom"/>
            </DataTemplate>
        </HubSection>
    </Hub>


</Grid>


目前,四个中心部分中有两个没有内容,但这与重点无关。提前谢谢你的帮助。

我想现在这是唯一的办法

我阅读了MSDN文档中的官方文章,似乎没有事件或属性来获取当前选定的项目


我同意李嘉图的观点,因为我知道没有办法获得选中的物品

作为一个工作循环,您可以添加
HubSection
Tabbed
事件。您可以知道点击了哪个
hubbsection

例如:

<Hub Header="Countries App" Foreground="#FFC3BFBF" SectionHeaderClick="HubSection_Click" Name="CountryHub">
    <HubSection x:Name="China" MinWidth="256" Height="460" Background="#FF343434" Header="China" IsHeaderInteractive="True" Tapped="{x:Bind HubSectionTapped}">
        <DataTemplate>
            <Grid Height="460" Width="256" VerticalAlignment="Bottom">
                <Image Source="Assets/dog.jpg" />
            </Grid>
        </DataTemplate>
    </HubSection>

    <HubSection x:Name ="Japan" MinWidth="256" Height="460" Background="#FF565454" Header="Japan" IsHeaderInteractive="True" Tapped="{x:Bind HubSectionTapped}">
        <DataTemplate>
            <Grid Height="460" Width="256" VerticalAlignment="Bottom">
                <Image Source="Assets/color.jpg" Height="169" />
            </Grid>
        </DataTemplate>
    </HubSection>
</Hub>
private void HubSectionTapped(object sender, TappedRoutedEventArgs e)
{
    var hubSectiona = sender as HubSection;
    var name = hubSectiona.Name;
    NaviagteMethod(name);
}

public void NaviagteMethod(string name)
{
    switch (name)
    {
        case "China":
            Frame.Navigate(typeof(SubtopicPage));
            break;

        case "Japan":
            Frame.Navigate(typeof(SubtopicPage));
            break;
    }
}