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

发布于 2024-11-07 09:03:10 字数 52 浏览 3 评论 0原文

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

What is the easiest way to set the font size of the panorama item header once so it can be used for all item headers in my app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

脸赞 2024-11-14 09:03:10

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

隐式样式将在 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>

There isn't a way to automatically do it for all headers in your app yet. You'll need to set the style for each one.

Implicit styling is coming in the Mango update and that should allow this to be done then.

Update
Here's what you can do now.

Create a global template style for the FontSzie you want. Something like:

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

Then in every PanoramaItem that I wish to have styled this way I set the HeaderTemplate:

<controls:PanoramaItem Header="first" HeaderTemplate="{StaticResource MyItemHeaderTemplate}">
    // ...
</controls:PanoramaItem>
初熏 2024-11-14 09:03:10

这对我来说也是一个难题。不过,我找到了一个非常简单的解决方案来处理您想要调整大小/字体粗细/字体...等等的每个头项。我插入了我当前正在从事的项目的片段。请注意控件的 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>

This had been a difficult issue for me as well. However I have found a pretty simple solution to take care of this for each head item you wantto resize/fontweight/font...so-on. I have inserted a snippet from a current project I have been working on. Take notice to the xaml portion for controls:PanoramaItem.HeaderTemplate. This is where the templete is modified for the header item. Good Luck!

<!--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>
胡渣熟男 2024-11-14 09:03:10

也许您可以尝试将其放在 下:

<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 -标题.aspx

Maybe you could try putting this in under the <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>

Found here: http://www.jstawski.com/archive/2010/10/25/change-windows-phone-7-panoramarsquos-control-title.aspx

说谎友 2024-11-14 09:03:10

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

You can create your own PanoramaItem Control and use generic.xaml to apply your custom PanoramaItem style.

public class MyPanoramaItem : Microsoft.Phone.Controls.PanoramaItem

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

Then you create 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>

And then use your custom Panorama like this:

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>

More about generic.xaml and its usage you can find here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文