修复页面上的页眉和页脚?

时间:2012-07-25 19:25:11

标签: windows-phone-7

Windows手机页面上是否可以有固定的页眉和页脚?我正在使用普通的XAML,而不是使用任何第三方控件。

由于

3 个答案:

答案 0 :(得分:5)

当然,这是代码和布局

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>

    <TextBlock Text="I AM HEADER" Grid.Row="0" FontSize="56"/>
    <StackPanel Grid.Row="1" >
        <TextBlock Text="Main content goes here. Main content goes here. " TextWrapping="Wrap" FontSize="56"/>
    </StackPanel>
    <TextBlock Text="I AM FOOTER" Grid.Row="2" FontSize="56"/>

</Grid>

enter image description here

答案 1 :(得分:1)

如果你想要一些可以反复使用的东西,我建议你创建一个自定义控件。任何页面都可以轻松使用此控件。

自定义控制:

public class HeaderFooterControl : ContentControl
{
    public object Header
    {
        get { return (object)GetValue(HeaderProperty); }
        set { SetValue(HeaderProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header", typeof(object), typeof(HeaderFooterControl), new PropertyMetadata(null));

    public object Footer
    {
        get { return (object)GetValue(FooterProperty); }
        set { SetValue(FooterProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty FooterProperty =
        DependencyProperty.Register("Footer", typeof(object), typeof(HeaderFooterControl), new PropertyMetadata(null));

    // TODO: Templates for Header and Footer
}

Xaml for Custom Control:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:MyLocalNamespace">
    <Style TargetType="controls:HeaderFooterControl">
        <Setter Property="Header" Value="Header info"/>
        <Setter Property="Footer" Value="Footer info"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:HeaderFooterControl">
                    <Grid Background="{TemplateBinding Background}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <ContentPresenter Content="{TemplateBinding Header}"/>
                        <ContentPresenter Content="{TemplateBinding Content}" Grid.Row="1"/>
                        <ContentPresenter Content="{TemplateBinding Footer}" Grid.Row="2"/>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

如果您这样填写页面,则可以使用该控件:

<phone:PhoneApplicationPage
    xmlns:controls="clr-namespace:MyLocalNamespace"
    <!-- Other parts of the page to declare (eg: FontSize, Foreground, etc)
    <controls:HeaderFooterControl Header="Hello Header!" Footer="Bottom of page!">
        <!-- Other content for your page here! -->
    </controls:HeaderFootControl>

您还可以通过设置可以设置的HeaderTemplate和FooterTemplate来添加此解决方案。您可以找到有关自定义控件here的更多信息。

答案 2 :(得分:0)

确保页面上的默认网格是2行。使它3 ..顶部和底部行设置为自动高度..中间设置为*