0

我开发了一个使用 Pivot 页面的应用程序。

我使用默认的 Pivot 模板创建了应用程序,背景由样式“PageBackgroundStyle”定义:

<phone:PhoneApplicationPage x:Class="PivotApp.Views.MainPage"
                        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"
                        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"
      Style="{StaticResource PageBackgroundStyle}">        

    <phone:Pivot x:Name="LocationPivot"
                 FontSize="{StaticResource LargeFontSize}"
                 LoadedPivotItem="Pivot_LoadedPivotItem">

        <phone:Pivot.Title>
            <TextBlock Text="Title"
                       FontSize="20"
                       Margin="0,0,0,10" />
        </phone:Pivot.Title>

        <phone:PivotItem  x:Name="one">
            <phone:PivotItem.Header>
                <TextBlock Text="one"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>

        <phone:PivotItem  x:Name="two">
            <phone:PivotItem.Header>
                <TextBlock Text="two"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>

        <phone:PivotItem  x:Name="three">
            <phone:PivotItem.Header>
                <TextBlock Text"three"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>
    </phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>

应用程序调用(在 OnNavigatedTo 内部)GetGeopositionAsync() 方法。上面的代码工作正常。

但是,如果我修改代码以显示图像背景,如下所示:

    <phone:PhoneApplicationPage x:Class="PivotApp.Views.MainPage"
                        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"
                        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">

    <Grid.Background>
        <ImageBrush Stretch="Fill"
                    ImageSource="/PivotApp;component/Assets/PanoramaBackground.png" />
    </Grid.Background>

    <phone:Pivot x:Name="LocationPivot"
                 FontSize="{StaticResource LargeFontSize}"
                 LoadedPivotItem="Pivot_LoadedPivotItem">

        <phone:Pivot.Title>
            <TextBlock Text="Title"
                       FontSize="20"
                       Margin="0,0,0,10" />
        </phone:Pivot.Title>

        <phone:PivotItem  x:Name="one">
            <phone:PivotItem.Header>
                <TextBlock Text="one"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>

        <phone:PivotItem  x:Name="two">
            <phone:PivotItem.Header>
                <TextBlock Text="two"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>

        <phone:PivotItem  x:Name="three">
            <phone:PivotItem.Header>
                <TextBlock Text"three"
                           FontSize="50" />
            </phone:PivotItem.Header>
            <Grid />
        </phone:PivotItem>
    </phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>

即,而不是由样式定义的背景:PageBackGroundStyle(在 App.xaml 中定义),我输入代码:

    <Grid.Background>
        <ImageBrush Stretch="Fill"
                    ImageSource="/PivotApp;component/Assets/PanoramaBackground.png" />
    </Grid.Background>

图像背景显示在 Pivot 页面上 OK,但是 GetGeopositionAsync() 方法被调用并且永远不会返回。

知道我做错了什么或枢轴/页面有问题吗?谢谢

4

0 回答 0