如何更改全景项目标题的字体大小?

9

最简单的方法是设置全局样式以一次性设置全应用程序中所有项目标题的字体大小。

4个回答

23

目前还没有一种能够自动设置应用程序中所有标题的样式的方法,您需要为每个标题设置样式。

随着 Mango 更新的到来,将会有隐式样式表功能,届时可能可以实现这一点。

更新:
以下是您现在可以做的事情。

创建一个全局模板样式以获得所需的字号。例如:

<Application.Resources>
    <DataTemplate x:Key="MyItemHeaderTemplate">
        <Grid>
            <ContentPresenter>
                <TextBlock Text="{Binding}" FontSize="20" />
            </ContentPresenter>
        </Grid>
    </DataTemplate>
</Application.Resources>

然后在我希望以这种方式进行样式设置的每个PanoramaItem中,我设置了HeaderTemplate:

<controls:PanoramaItem Header="first" HeaderTemplate="{StaticResource MyItemHeaderTemplate}">
    // ...
</controls:PanoramaItem>

“set style”:您是指为HeaderTemplate设置DataTemplate吗?如果是这样,我需要为我的4个全景项中的每个项标题创建4个DataTemplates,因为每个项标题都不同吗?还是我可以以某种方式将一个单一的DataTemplate绑定到PanoramaItem.Header属性? - Buju
啊,谢谢。我漏掉了 Text="{Binding}" 这一部分……我不知道如何从 DataTemplate 内部访问标题字符串。如果再次发生这样的情况,有没有办法查找可以在 DataTemplate 中绑定的属性? - Buju

5

这对我来说也是个棘手的问题。不过,我已经找到了一种相当简单的解决方案,用于调整每个标题项的大小/字重/字体等等。我插入了一个来自我正在进行的当前项目的片段。请注意控件:PanoramaItem.HeaderTemplate下的xaml部分。这是修改标题项模板的位置。祝你好运!

<!--Panorama item one-->
        <controls:PanoramaItem Header="Locations">   
            <Grid>
                <ListBox Height="498" HorizontalAlignment="Left" Margin="2,0,0,0" Name="listBox1" VerticalAlignment="Top" Width="424" />
            </Grid>

            <controls:PanoramaItem.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="55" FontFamily="Segoe WP Bold" Foreground="Black" TextAlignment="Left" FontWeight="Normal" FontStyle="Italic" />
                </DataTemplate>
            </controls:PanoramaItem.HeaderTemplate>


        </controls:PanoramaItem>

2
也许你可以尝试将这个放在<controls:Panorama>标签下面:
<controls:Panorama.TitleTemplate>
  <DataTemplate>
     <TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="150" Margin="0,20,0,0" FontWeight="Bold" />
  </DataTemplate>
</controls:Panorama.TitleTemplate>

这里找到了一个关于如何更改 Windows Phone 7 平铺控件标题的文章:http://www.jstawski.com/archive/2010/10/25/change-windows-phone-7-panoramarsquos-control-title.aspx


1

您可以创建自己的 PanoramaItem 控件,并使用 generic.xaml 应用您的自定义 PanoramaItem 样式。

public class MyPanoramaItem : Microsoft.Phone.Controls.PanoramaItem

    {
        public MyPanoramaItem()
        {
            DefaultStyleKey = typeof(MyPanoramaItem); 
        }
    }

然后创建Themes\Generic.xaml文件

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:YourProjectNamespace"> 

    <Style TargetType="local:MyPanoramaItem">
        <!—your custom PanoramaItem style-->    
    </Style> 
</ResourceDictionary>

然后像这样使用您的自定义全景图:

xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:local="clr-namespace:YourProjectNamespace"

<Grid x:Name="LayoutRoot" Background="Transparent"> 
        <!--Panorama control-->
        <controls:Panorama Title="my application">
            <controls:Panorama.Background>
                <ImageBrush ImageSource="PanoramaBackground.png"/>
            </controls:Panorama.Background>

            <!--Panorama item one-->
            <local:MyPanoramaItem Header="first item">
            </ local:MyPanoramaItem >
        </controls:Panorama>

关于generic.xaml及其使用的更多信息,您可以在这里找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接