MAUI TableView标题无法显示大写字母(仅Windows端)求助
MAUI Windows端TableView标题自动转为小写的解决方法
Windows平台下使用MAUI内置TableView时,设置TableRoot或TableSection的Title属性(如Title="Example Text"),标题会自动显示为全小写,Android平台无此问题。
用户示例代码:
<TableView Intent="Menu" HorizontalOptions="Center"> <TableRoot Title="Example Text"> <TableSection> <TextCell Text="First Example" Detail="Example details"/> <TextCell Text="Second Example" Detail="Example details"/> </TableSection> </TableRoot> </TableView>
问题原因
Windows端MAUI的TableView默认样式中,TableRootHeader和TableSectionHeader的文本被设置了强制小写的字符转换规则,导致自定义的Title大小写被覆盖。
解决方法
通过自定义Windows平台的样式,取消文本的强制转换:
- 打开
Platforms/Windows/App.xaml文件,添加以下样式资源:
<Application.Resources> <!-- 修复TableRoot标题小写问题 --> <Style TargetType="controls:TableRootHeader"> <Setter Property="Typography.Capitals" Value="Normal"/> </Style> <!-- 修复TableSection标题小写问题(如果需要) --> <Style TargetType="controls:TableSectionHeader"> <Setter Property="Typography.Capitals" Value="Normal"/> </Style> </Application.Resources>
- 如果仅需在单个页面生效,也可以将上述样式添加到页面的
Resources节点中。
效果验证
应用样式后,TableView的标题会严格按照Title属性设置的文本显示大小写,不再自动转为小写。
内容的提问来源于stack exchange,提问作者Andrew
相关产品推荐
相关产品推荐

