在Windows 8中添加顶部导航栏-教程问题

本文关键字:教程 问题 导航 顶部 Windows 添加 | 更新日期: 2023-09-27 17:49:35

我正在试用WIndows 8的教程。我需要加一个Navigation Bar。步骤如下:

以下内容来自教程

  1. 在解决方案资源管理器中,双击主页。
  2. 在文档大纲中,选择pageRoot元素。
  3. 在属性面板中,单击属性按钮()显示属性视图。
  4. 在常用属性面板中,找到TopAppBar属性。
  5. 点击TopAppBar旁边的新建按钮。AppBar控件被添加到页面中。
  6. 在文档大纲中,展开TopAppBar属性。
  7. 选择"photoPageButton"元素,把它拖到AppBar上,然后放下。
  8. 在布局的属性面板中,设置HorizontalAlignment属性为右()。
  9. 按F5构建并运行应用程序。要测试应用程序栏,右键单击主页面。应用程序栏在屏幕顶部打开。

I双击MainPage.xaml,然后在Document Outline中选择pageRoot。在properties窗口展开Common,点击TopAppBar旁边的New

它在它下面添加了其他几个FieldsAllow Drop, BackgroundCache Mode是其中的一些。然后在Document Outline中,我将按钮拖动到TopAddBar下的AppBar。将HorizontalAlignment更改为Right,构建并执行应用程序。但是我没有看到这个按钮被添加到顶部的导航栏。我哪里做错了?

更新

<Page.Resources>
    <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
    <x:String x:Key="AppName">My Application</x:String>
</Page.Resources>
<common:LayoutAwarePage.TopAppBar>
    <AppBar Background="#E5A41D1D" AllowDrop="True" BorderBrush="#E5C5A7A7" HorizontalAlignment="Right">
        <Button Content="Next Page&#xD;&#xA;" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="230" Height="70" Background="#FF12668D" FontFamily="Shruti" FontSize="36" Click="Button_Click_2"/>
    </AppBar>
</common:LayoutAwarePage.TopAppBar>
<!--
    This grid acts as a root panel for the page that defines two rows:
    * Row 0 contains the back button and page title
    * Row 1 contains the rest of the page layout
-->
<Grid Style="{StaticResource LayoutRootStyle}" Background="#FF282D40">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!-- Back button and page title -->
    <!-- Back button and page title -->
    <!-- Back button and page title -->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
        <TextBlock x:Name="pageTitle" Grid.Column="1" Text="Welcome !!! " Style="{StaticResource PageHeaderTextStyle}" Foreground="#DE2374AC"/>
    </Grid>
    <VisualStateManager.VisualStateGroups>
        <!-- Visual states reflect the application's view state -->
        <VisualStateGroup x:Name="ApplicationViewStates">
            <VisualState x:Name="FullScreenLandscape"/>
            <VisualState x:Name="Filled"/>
            <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
            <VisualState x:Name="FullScreenPortrait">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <!-- The back button and title have different styles when snapped -->
            <VisualState x:Name="Snapped">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>

在Windows 8中添加顶部导航栏-教程问题

您正在遵循本教程,对吗?看起来你把错误的按钮拖到了TopAppBar上。

你应该拖动的按钮被命名为photoPageButton(它的x:Name属性)。相反,你的TopAppBar中的按钮没有名称,呈现的文本是"下一页"。

当你把photoagebutton拖到TopAppBar上后,你的TopAppBar的XAML标记应该看起来像这样:

<common:LayoutAwarePage.TopAppBar>
    <AppBar HorizontalAlignment="Right">
        <Button x:Name="photoPageButton" Content="Go to photo page"/>
    </AppBar>
</common:LayoutAwarePage.TopAppBar>

在教程中进一步学习并为按钮应用样式后,您的TopAppBar标记将看起来像这样:

<common:LayoutAwarePage.TopAppBar>
    <AppBar HorizontalAlignment="Right">
        <Button x:Name="photoPageButton" 
            Click="photoPageButton_Click"
            HorizontalAlignment="Right" 
            Style="{StaticResource PicturesAppBarButtonStyle}"/>
    </AppBar>
</common:LayoutAwarePage.TopAppBar>

在那里有其他AppBar设置也是完全可以接受的-背景,BorderBrush;这些都是对color和AllowDrop默认值为true的无害更改,我相信,所以这也很好。