[英]How to change the TextSize and Casing in TableView TableSection in Xamarin.UWP
I have a CustomTableView
control which I made from the Xamarin TableView
.我有一个使用 Xamarin
TableView
制作的CustomTableView
控件。 I used custom renderers to change the TextSize and Boldness for Android and iOS with code inspired by this post .我使用自定义渲染与受此启发代码更改TEXTSIZE和勇气Android和iOS 职位。
I want to do the same for UWP, but I have no idea how to achieve this.我想为 UWP 做同样的事情,但我不知道如何实现这一点。 Specifically I want to make the Text in the TableSections bigger and Make this text start with Uppercase letters as well.
具体来说,我想让 TableSections 中的文本更大,并使该文本也以大写字母开头。 Any ideas on how I could achieve this would be highly appreciated.
任何关于我如何实现这一目标的想法都将受到高度赞赏。
How to change the TextSize and Casing in TableView TableSection in Xamarin.UWP
如何在 Xamarin.UWP 中更改 TableView TableSection 中的 TextSize 和大小写
Please check this code line , Xamarin places TextBlock in the TableSection
DataTemplate
.请检查此代码行,Xamarin 将 TextBlock 放在
TableSection
DataTemplate
。 If you want to edit the properties you can do that by adding a DataTemplate
to your App.Xaml
file in the UWP project.如果要编辑属性,可以通过将
DataTemplate
添加到 UWP 项目中的App.Xaml
文件来实现。 If you want to edit FontSize
, you can use the code below.如果要编辑
FontSize
,可以使用下面的代码。 (Note the FontSize property) . (注意 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>
In the UWP Renderer for your customTableView you can set listview.GroupStyle.FirstOrDefault().HeaderTemplate
manually like below.在您的 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"];
}
}
}
Unfortunately, TableSection
does not support inherit, so we can't extend dependency property for it.不幸的是,
TableSection
不支持继承,所以我们不能为它扩展依赖属性。
As for the casing of the Title
, you can simply remove the Converter={StaticResource LowerConverter}
from the Text
, and set the Title
for the TableView
to a string with with whatever casing you like and it will not be converted to lowercase.至于
Title
的大小写,您可以简单地从Text
删除Converter={StaticResource LowerConverter}
,并将TableView
的Title
设置为带有您喜欢的任何大小写的字符串,并且不会转换为小写。 So it would end up looking like this:所以它最终看起来像这样:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.