簡體   English   中英

Windows Phone應用程序欄隱藏頁面內容

[英]Windows Phone application bar hides page content

我正在嘗試Windows Phone 8的開發,並且從這里和那里的示例中竊取了一個小應用程序。 但是,我偶然發現了一個困擾不已的問題:當我向頁面中添加應用程序欄(在XAML或C#中)時,它隱藏了內容的底部,或者無法向下滾動。

我的XAML是:

<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
x:Class="MyApp.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock x:Name="appNameText" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <maps:Map x:Name="locationMap" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="446" Height="347">
            <maptk:MapExtensions.Children>
                <maptk:Pushpin Name="MyLocation" Visibility="Collapsed" />
            </maptk:MapExtensions.Children>
        </maps:Map>
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="165,362,0,0" VerticalAlignment="Top" Width="291" />
        <TextBlock x:Name="longitudeText" HorizontalAlignment="Left" Margin="338,462,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="longitude placeholder"/>
        <TextBlock x:Name="latitudeText" HorizontalAlignment="Left" Margin="338,507,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="latitude placeholder"/>

        <toolkit:ToggleSwitch x:Name="switch1" IsChecked="True" Content="First switch" Margin="165,424,24,76"/>
        <toolkit:ToggleSwitch x:Name="switch2" Margin="114,482,24,10" Content="Second switch" IsChecked="True"/>

    </Grid>

</Grid>

以及創建應用欄的代碼:

        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        ApplicationBar = new ApplicationBar();

    //    // Create a new button and set the text value to the localized string from AppResources.
        ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        appBarButton.Text = AppResources.AppBarButtonText;
        appBarButton.Click += appBarButton_Click;
        ApplicationBar.Buttons.Add(appBarButton);

    //    // Create a new menu item with the localized string from AppResources.
        ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        ApplicationBar.MenuItems.Add(appBarMenuItem);

沒有應用欄的結果: 沒有應用欄

並添加了應用欄: 帶有應用欄

請注意缺少交換機的標簽。 (實際上,底部開關本身也被隱藏了,但是看起來好像是在漫不經心地擺弄了“固定”開關。

所以,長話短說:有人可以指出出現這種異常的原因是我做錯了什么嗎?

頁面不會自動包含ScrollViewer,因此您需要在要滾動的元素周圍添加一個(在您的情況下,我認為這意味着在LayoutRoot網格周圍)。

ScrollViewer.VerticalScrollBarVisibility="Auto"是ScrollViewer用於確定是否可見的東西,但是由於根本沒有ScrollViewer,所以它什么也不做。 (這是一個附加屬性,例如,類似於Grid.Row,僅當元素位於Grid中時才有用。)

在我所知的情況下,只有一種情況是應用程序欄實際上位於頁面的前面:當AppBar的不透明度不是100%時。 在這種情況下,頁面實際上位於頁面后面,因此您必須自己管理可見的位置/位置/方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM