我无法更改列表视图项目或列标题的字体大小
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这听起来很像您的 GridViewColumn 有一个隐式样式,它会覆盖您在本地所做的更改。
在设计时,不会考虑隐式样式(可能出于各种原因),但在运行时会考虑,并且您会得到这种奇怪的行为。
我首先查看 App.xaml 的资源部分,然后向上移动,直到到达我关心的控件。
添加:隐式样式:
如果您想在本地定义隐式样式而不覆盖链上更高位置的另一个隐式样式集,您可以这样做:
它将继承隐式样式并添加更改本地用户控件。
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:
If you ever want to define an implicit style locally without overwriting another implicit style set higher up the chain, you can do this:
It will inherit the implicit style in place and add changes for the local UserControl.
对我来说,以下内容适用于标题和项目:
但不知道您的情况可能出了什么问题......
For me the following works for both header and items:
No idea what could be wrong in your case though...
如果您只想设置标题大小,请尝试此解决方案
或使用 @HB 解决方案
希望这有帮助
if you want only set the header size, then try this solution
or use @H.B. solution
hope this helps