如何在 Xamarin.UWP 中更改 TableView TableSection 中的 TextSize 和大小写
请检查此 code line,Xamarin 将 TextBlock 放置在 TableSection DataTemplate 中。如果要编辑属性,可以通过在 UWP 项目中的 App.Xaml 文件中添加 DataTemplate 来实现。如果要编辑FontSize,可以使用下面的代码。 (注意 FontSize 属性)。
<Application.Resources>
<DataTemplate x:Key="TableSectionOne">
<TextBlock
Margin="0,20,0,0"
FontSize="55"
Foreground="{Binding TextColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}"
Style="{ThemeResource SubtitleTextBlockStyle}"
Text="{Binding Title, Converter={StaticResource LowerConverter}}"
Visibility="{Binding Text, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource CollapseWhenEmpty}}" />
</DataTemplate>
</Application.Resources>
在您的 customTableView 的 UWP 渲染器中,您可以手动设置 listview.GroupStyle.FirstOrDefault().HeaderTemplate,如下所示。
class CustomTableViewRender : TableViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
{
base.OnElementChanged(e);
if(Control != null)
{
var listview = Control as Windows.UI.Xaml.Controls.ListView;
listview.GroupStyle.FirstOrDefault().HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TableSectionOne"];
}
}
}
很遗憾,TableSection 不支持继承,因此我们无法为其扩展依赖属性。
至于Title 的大小写,您可以简单地从Text 中删除Converter={StaticResource LowerConverter},并将TableView 的Title 设置为您喜欢的任何大小写的字符串不转换为小写。所以它最终看起来像这样:
<Application.Resources>
<DataTemplate x:Key="TableSectionOne">
<TextBlock
Margin="0,20,0,0"
FontSize="55"
Foreground="{Binding TextColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}"
Style="{ThemeResource SubtitleTextBlockStyle}"
Text="{Binding Title}"
Visibility="{Binding Text, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource CollapseWhenEmpty}}" />
</DataTemplate>
</Application.Resources>