【问题标题】:How to change font size of Panorama item header?如何更改全景项目标题的字体大小?
【发布时间】:2011-08-26 12:22:34
【问题描述】:

设置全景项目标题的字体大小以便它可以用于我的应用程序中的所有项目标题的最简单方法是什么?

【问题讨论】:

    标签: windows-phone-7 font-size panorama-control


    【解决方案1】:

    目前还没有一种方法可以自动为您应用中的所有标题执行此操作。您需要为每一个设置样式。

    隐式样式将在 Mango 更新中出现,届时应该可以做到这一点。

    更新
    这是您现在可以执行的操作。

    为您想要的 FontSzie 创建一个全局模板样式。比如:

    <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 个 DataTemplate,因为每个项目标题都不同?或者我可以以某种方式将一个 DataTemplate 绑定到 PanoramaItem.Header 属性吗?
    • 啊谢谢。我错过了 Text="{Binding}" 的部分......我不知道如何从 DataTemplate 内部访问标题字符串。如果这样的事情再次发生在我身上,有没有办法查找我可以在 DataTemplate 中绑定哪些属性?
    【解决方案2】:

    这对我来说也是一个难题。但是,我找到了一个非常简单的解决方案来处理您要调整大小/字体重量/字体...等等的每个头部项目。我从我一直在从事的当前项目中插入了一个 sn-p。请注意控件的 xaml 部分:PanoramaItem.HeaderTemplate。这是为标题项目修改模板的地方。祝你好运!

    <!--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>
    

    【讨论】:

      【解决方案3】:

      也许您可以尝试将其放在&lt;controls:Panorama&gt; 下:

      <controls:Panorama.TitleTemplate>
        <DataTemplate>
           <TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="150" Margin="0,20,0,0" FontWeight="Bold" />
        </DataTemplate>
      </controls:Panorama.TitleTemplate>
      

      在这里找到:http://www.jstawski.com/archive/2010/10/25/change-windows-phone-7-panoramarsquos-control-title.aspx

      【讨论】:

        【解决方案4】:

        您可以创建自己的 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 及其用法的更多信息,您可以找到 here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-13
          • 2012-01-16
          • 1970-01-01
          • 1970-01-01
          • 2019-02-05
          相关资源
          最近更新 更多