简体   繁体   English

如何在 Xamarin.UWP 中更改 TableView TableSection 中的 TextSize 和大小写

[英]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} ,并将TableViewTitle设置为带有您喜欢的任何大小写的字符串,并且不会转换为小写。 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.

相关问题 如何在 Xamarin.UWP 应用程序中实现 LongPress? - How do I implement LongPress in a Xamarin.UWP application? 如何在 Xamarin.UWP 的另一个内容中绑定内容? - How to bind content inside another content in Xamarin.UWP? 发行模式下的Xamarin.UWP运行时错误 - Xamarin.UWP Runtime error in Release mode Xamarin.UWP启动期间未处理的异常 - Xamarin.UWP Unhandled Exception during launch 如何在 Xamarin.UWP 中调整大小和减小大小(使用压缩质量值) - How to resize and reduce size (using a compression quality value) in Xamarin.UWP SQLite 无法在 Xamarin.UWP 应用中打开数据库文件 - SQLite Could not open database file in Xamarin.UWP app 当前不支持指针类型数组Xamarin.UWP错误 - Arrays of pointer types are currently not supported Xamarin.UWP error 如何使用自定义渲染器更改TableSection文本颜色 - Xamarin.Forms C# - How to change the TableSection text color with a custom renderer - Xamarin.Forms C# 如何在 Xamarin 的 ViewModel Renderer 中获取 TableSection 的 TextColor 值 - How to get the TextColor value of a TableSection in my ViewModel Renderer in Xamarin Xamarin Forms-如何创建自定义渲染以使Android上的TableSection具有页脚? - Xamarin Forms - How to create custom render to give TableSection on Android a footer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM