Windows Phone 8 - 中心全景 Item.Header

2024-01-21

我正在开发适用于 Windows Phone 8 的全景应用程序,但遇到了一个小问题。我在其中一个 Panorama.Item 的标题中添加了一张图像(它显示得很好),但我希望它居中而不是左对齐。我什至不知道这是否可能,或者您是否根本无法更改对齐方式。这是我正在讨论的标题的代码:

<phone:PanoramaItem.Header>
   <Image x:Name="Logo" Height="100" HorizontalAlignment="Center" Tap="Logo_Tap" />
</phone:PanoramaItem.Header>

不幸的是,Horizo​​ntalAlignment="Center"-Property 似乎没有这样做。任何帮助,将不胜感激。


我会避免使用硬编码宽度。执行此操作的正确方法是覆盖PanoramaItem,像这样(他们的关键部分是改变HorizontalAlignment on the header ContentControl)

<ControlTemplate x:Key="CenteredHeaderPanoramaItemTemplate" TargetType="phone:PanoramaItem">
    <Grid Background="{TemplateBinding Background}" Margin="12,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ContentControl x:Name="header" CharacterSpacing="-35" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" FontSize="66" FontFamily="{StaticResource PhoneFontFamilySemiLight}" Margin="12,-2,0,38" HorizontalAlignment="Stretch">
            <ContentControl.RenderTransform>
                <TranslateTransform x:Name="headerTransform"/>
            </ContentControl.RenderTransform>
        </ContentControl>
        <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Grid.Row="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Grid>
</ControlTemplate>

然后只需使用 StaticResource 分配模板

<phone:PanoramaItem Template="{StaticResource CenteredHeaderPanoramaItemTemplate}">
    <phone:PanoramaItem.Header>
        <Image x:Name="Logo" Height="100" HorizontalAlignment="Center" Tap="Logo_Tap" />
    </phone:PanoramaItem.Header>
    <Grid x:Name="PanoramaItemContent">
    </Grid>
</phone:PanoramaItem>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows Phone 8 - 中心全景 Item.Header 的相关文章

随机推荐