如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2117字,纯文字阅读大概需要4分钟。
内容图文
![如何使用自定义渲染器更改TableSection文本颜色-Xamarin.Forms C#](/upload/InfoBanner/zyjiaocheng/664/66b45dbd441f4a238c42f8219feb6ae9.jpg)
我有一个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#所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。