如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#

如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#,第1张

概述我有一个TableView在根目录中具有3个TableSections:vartableView=newTableView{RowHeight=60,Root=newTableRoot{firstTableSection,secondTableSection,thirdTableSection,}}varfirstTableSection=newTableSection("First"){

我有一个tableVIEw在根目录中具有3个tableSections:

var tableVIEw = new tableVIEw{  RowHeight = 60,  Root = new tableRoot  {    firsttableSection,    secondtableSection,    thirdtableSection,  }}var firsttableSection = new tableSection("First"){  // Cells}var firsttableSection = new tableSection("First"){  // Cells}var firsttableSection = new tableSection("First"){  // Cells}

如何使用自定义渲染器更改tableSection文本的文本颜色?

public class TesttableVIEWrenderer : Xamarin.Forms.Platform.AndroID.tableVIEWrenderer{    protected overrIDe voID OnElementChanged(Xamarin.Forms.Platform.AndroID.ElementChangedEventArgs<Xamarin.Forms.tableVIEw> e)    {        base.OnElementChanged(e);        // Not sure how to add this property here    }}

解决方法:

我结束了使用此解决方案:

https://forums.xamarin.com/discussion/32379/changing-the-title-color-of-a-tablesection

它依赖于两个自定义渲染器:

[assembly: ExportRenderer(typeof(tableVIEw), typeof(CustomtableVIEw))]namespace APP.DroID{    public class CustomtableVIEw : tableVIEWrenderer    {        protected overrIDe tableviewmodelRenderer GetModelRenderer(global::AndroID.Widget.ListVIEw ListVIEw, tableVIEw vIEw)        {            return new CustomtableviewmodelRenderer(this.Context, ListVIEw, vIEw);        }    }}

[assembly: ExportRenderer(typeof(tableviewmodelRenderer), typeof(CustomtableviewmodelRenderer))]namespace APP.DroID{    public class CustomtableviewmodelRenderer : tableviewmodelRenderer    {        public CustomtableviewmodelRenderer(Context Context, global::AndroID.Widget.ListVIEw ListVIEw, tableVIEw VIEw)            : base(Context, ListVIEw, VIEw)        { }        public overrIDe global::AndroID.VIEws.VIEw GetVIEw(int position, global::AndroID.VIEws.VIEw convertVIEw, VIEwGroup parent)        {            var vIEw = base.GetVIEw(position, convertVIEw, parent);            var element = this.GetCellForposition(position);            if (element.GetType() == typeof(TextCell))            {                try                {                    var text = ((((vIEw as linearLayout).GetChildAt(0) as linearLayout).GetChildAt(1) as linearLayout).GetChildAt(0) as TextVIEw);                    var divIDer = (vIEw as linearLayout).GetChildAt(1);                    text.SetTextcolor(AndroID.Graphics.color.Rgb(50, 50, 50));                    divIDer.SetBackgroundcolor(AndroID.Graphics.color.Rgb(150, 150, 150));                }                catch (Exception) { }            }            return vIEw;        }    }}
总结

以上是内存溢出为你收集整理的如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#全部内容,希望文章能够帮你解决如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120647.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存