Xamarin Forms - sectionIndexTitlesForTableView 自定义

Xamarin Forms - sectionIndexTitlesForTableView customisation

我有一个 Xamarin Forms 应用程序,客户真的想在其中使用 iOS 'scrolling alphabet index',但 Android

不支持

因此我有两个平台的 UI,但我现在正尝试更改 iOS

上文本的默认颜色

我研究了如何执行此操作,它似乎需要自定义 TableiOS 平台上的视图

How change iOS TableView index Color?

   tableView.sectionIndexColor = UIColor.red
   tableView.sectionIndexBackgroundColor = UIColor.clear

我的问题是如何在视图中使用它?因为让它在 ioS 上工作所需的唯一代码可以简单地由 Xaml

显示
<ListView Grid.Row="1"
          x:Name="ItemList"
          IsGroupingEnabled="True"
          ItemsSource="{Binding allItems}"
          GroupDisplayBinding="{Binding Item}"
          GroupShortNameBinding="{Binding IndexLetter}"
          ItemTapped="Handle_ItemTapped"
          CachingStrategy="RecycleElement"
          BackgroundColor="Black"
          HasUnevenRows="True">

这是一个列表视图,而不是 table 视图,因此我可以在 Xamarin Forms 的什么地方引用自定义 Table 视图渲染器来更改 [=] 上的文本颜色27=]?

您可以使用 Custom Renderer 来实现它。

using UIKit;

using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

using xxx.iOS;


[assembly:ExportRenderer(typeof(ListView),typeof(MyTableViewRenderer))]
namespace xxx.iOS
{
    public class MyTableViewRenderer:ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if(Control!=null)
            {
                Control.SectionIndexColor = UIColor.Red;
                Control.SectionIndexBackgroundColor = UIColor.Clear;
            }
        }
    }
}