【问题标题】:Best practise to navigation in windows phone 8.1[RT] xamlwindows phone 8.1 [RT] xaml 中导航的最佳实践
【发布时间】:2015-11-05 12:33:00
【问题描述】:

您好,我正在使用 windows phone 8.1[RT] 应用程序,我只是浏览页面。但我发现我们可以在 xaml 中使用 Frame 的新选项也像这样

  <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="120"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Border Background="White">

    </Border>
    <Button Content="next" Click="Button_Click" Background="Black" />

    <Grid Grid.Row="1">

        <Frame x:Name="Page1Frame" Background="Black" >
            <StackPanel>
                <Rectangle Height="100" Width="100" Fill="Red" Margin="5" />

                <Rectangle Height="100" Width="100" Fill="Red" Margin="5" />
                <Rectangle Height="100" Width="100" Fill="Red" Margin="5" />
                <Rectangle Height="100" Width="100" Fill="Red" Margin="5" />
            </StackPanel>
        </Frame>
    </Grid>

</Grid>

并像这样导航这个框架

private void Button_Click(object sender, RoutedEventArgs e)
{
        Page1Frame.Navigate(typeof(BlankPage1));
}

在这个例子中,我的 120 高度网格保持不变,只是导航框架。 我只想知道使用哪种最佳做法? 谢谢你。

【问题讨论】:

    标签: c# xaml navigation windows-phone-8.1 frame


    【解决方案1】:

    Page 是 page,Frame 是 frame,它们是不同的。

    假设你的当前页面名为 MainPage,如果你想留在 MainPage 并更改根网格第 1 行的网格内容,你应该使用:

     Page1Frame.Navigate(typeof(BlankPage1));
    

    如果你想离开 MainPage 去另一个页面,你应该使用:

    var rootFrame = Window.Current.Content as Frame; 
    rootFrame.Navigate(typeof(BlankPage1));
    

    在这种情况下,您看到的是一个没有 120 高度网格的空白页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 2020-01-09
      • 1970-01-01
      相关资源
      最近更新 更多