我无法更改列表视图项目或列标题的字体大小

发布于 2024-12-20 05:17:55 字数 766 浏览 1 评论 0原文

    <ListView x:Name="lstProductionOrders">
         <ListView.View>
              <GridView>
                   <GridViewColumn Header="Production Order:"/>
                        ...

我已经使用 textelement 在网格上设置了字体大小,我已经在列表视图、列标题上设置了它,通过样式,通过使用 BasedOn 的样式。我什至放入了一个全新的测试窗口,其中没有其他代码,但有默认代码和按照上面相同方式创建的列表视图。使用以上所有内容,字体会在设计时发生变化,但不会在运行时发生变化。

我只有大约 6 个月的 WPF/XAML 经验,所以我可能正在寻找错误的东西。是否有某种字体大小的全局设置或任何人都可以想到的会导致它被覆盖的设置。

作为记录,我使用测试窗口,没有基类。

----------编辑----------

这是应用程序中问题的根源。 xaml

<Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Times New Roman"/>
        <Setter Property="FontSize" Value="20"/>
</Style>
    <ListView x:Name="lstProductionOrders">
         <ListView.View>
              <GridView>
                   <GridViewColumn Header="Production Order:"/>
                        ...

I've set the fontsize on the grid, using textelement, I've set it on the listview, the columnheader, through styles, through styles using BasedOn. I even put in a brand new test window that had no other code in it but the default code and a listview created the same way above. Using all of the above, the font changes in design-time but not in run-time.

I've only got about 6 months of WPF/XAML experience, so I may be looking for the wrong thing. Is there some kind of global setting for fontsize or anything anyone can think of that would be causing this to be overridden.

For the record, I with the test window, there are no base classes.

----------EDIT----------

This was the source of the problem in App. xaml

<Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Times New Roman"/>
        <Setter Property="FontSize" Value="20"/>
</Style>

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

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

发布评论

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

评论(3

情域 2024-12-27 05:17:55

这听起来很像您的 GridViewColumn 有一个隐式样式,它会覆盖您在本地所做的更改。

在设计时,不会考虑隐式样式(可能出于各种原因),但在运行时会考虑,并且您会得到这种奇怪的行为。

我首先查看 App.xaml 的资源部分,然后向上移动,直到到达我关心的控件。

添加:隐式样式:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock">
         <Setter Property="FontSize" Value="40" /> <!-- stupid value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

如果您想在本地定义隐式样式而不覆盖链上更高位置的另一个隐式样式集,您可以这样做:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
         <Setter Property="FontSize" Value="60" /> <!-- ridiculous value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

它将继承隐式样式并添加更改本地用户控件。

This sounds a lot like you have an implicit style for GridViewColumn that overwrites changes you made locally.

At design time, that implicit style is not taken into account (could be for various reasons), but at runtime it is, and you get that strange behavior.

I would start by looking into App.xaml's Resources section, then move upwards until I reach the control I care about.

Addition: implicit styles:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock">
         <Setter Property="FontSize" Value="40" /> <!-- stupid value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

If you ever want to define an implicit style locally without overwriting another implicit style set higher up the chain, you can do this:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
         <Setter Property="FontSize" Value="60" /> <!-- ridiculous value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

It will inherit the implicit style in place and add changes for the local UserControl.

栖迟 2024-12-27 05:17:55

对我来说,以下内容适用于标题和项目:

<ListView ItemsSource="{Binding Source={StaticResource Items}}"
          TextElement.FontSize="16">
    <!-- ... -->

但不知道您的情况可能出了什么问题......

For me the following works for both header and items:

<ListView ItemsSource="{Binding Source={StaticResource Items}}"
          TextElement.FontSize="16">
    <!-- ... -->

No idea what could be wrong in your case though...

国粹 2024-12-27 05:17:55

如果您只想设置标题大小,请尝试此解决方案
或使用 @HB 解决方案

<ListView x:Name="lstProductionOrders" >
    <ListView.View>
        <GridView>
            <GridViewColumn>
                <GridViewColumnHeader TextElement.FontSize="16">Production Order:/GridViewColumnHeader>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

在此处输入图像描述

希望这有帮助

if you want only set the header size, then try this solution
or use @H.B. solution

<ListView x:Name="lstProductionOrders" >
    <ListView.View>
        <GridView>
            <GridViewColumn>
                <GridViewColumnHeader TextElement.FontSize="16">Production Order:/GridViewColumnHeader>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

enter image description here

hope this helps

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