我制作了一个包含很多页面的应用程序。每个页面由两部分组成:页面之间共享的相同部分(一些网格、控件和事件等),以及包含每个页面不同内容的单独部分。
现在我想知道我是否可以使用包含第一部分的“主框架”,所以我只需要创建包含第二部分的页面(在通用应用程序中他们有 Frame.Navigate() 但我没有不知道 WP8 有没有)。
最佳答案
在您的 App.xaml.cs
中实际上定义了一个 PhoneApplicationFrame
(称为 RootFrame
)。
您可以为其创建默认样式并在其ControlTemplate
中添加共享内容。
下面的代码来 self 的应用程序 627.AM。您可以看到我将 Logo (AnimatedLogoView
) 放在那里,这样我就不需要在每个页面上都复制它们。
<Style TargetType="phone:PhoneApplicationFrame">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:PhoneApplicationFrame">
<Border x:Name="ClientArea" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" d:DesignWidth="480" d:DesignHeight="800" >
<Border.Resources>
<Storyboard x:Name="ShowGlobalMessageAnimation"/>
</Border.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition/>
</Grid.RowDefinitions>
<views:AnimatedLogoView x:Name="Logo" />
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Grid.RowSpan="2" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
希望这对您有所帮助!
关于c# - 为 Windows Phone 8 创建主框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25736626/