diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/TableViewCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/TableViewCoreGalleryPage.cs index f5c7a0774cf..0b050e099e3 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/TableViewCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/TableViewCoreGalleryPage.cs @@ -1,3 +1,5 @@ +using Xamarin.Forms.CustomAttributes; + namespace Xamarin.Forms.Controls { internal class TableViewCoreGalleryPage : CoreGalleryPage @@ -11,6 +13,32 @@ protected override bool SupportsFocus protected override void Build (StackLayout stackLayout) { base.Build (stackLayout); + + var tableSectionContainer = new ViewContainer(Test.TableView.TableSection, new TableView()); + var section = new TableSection("Test") + { + TextColor = Color.Red + }; + + section.Add(new TextCell { Text = "Worked!" }); + + var section1 = new TableSection("Testing") + { + TextColor = Color.Green + }; + + section1.Add(new TextCell { Text = "Workeding!" }); + + var section2 = new TableSection("Test old") + { + new TextCell { Text = "Worked old!" } + }; + + tableSectionContainer.View.Root.Add(section); + tableSectionContainer.View.Root.Add(section1); + tableSectionContainer.View.Root.Add(section2); + + Add(tableSectionContainer); } } } \ No newline at end of file diff --git a/Xamarin.Forms.Core/ITableModel.cs b/Xamarin.Forms.Core/ITableModel.cs index 4778b9086c3..bcca094c601 100644 --- a/Xamarin.Forms.Core/ITableModel.cs +++ b/Xamarin.Forms.Core/ITableModel.cs @@ -9,6 +9,7 @@ public interface ITableModel int GetSectionCount(); string[] GetSectionIndexTitles(); string GetSectionTitle(int section); + Color GetSectionTextColor(int section); void RowLongPressed(int section, int row); void RowSelected(object item); void RowSelected(int section, int row); diff --git a/Xamarin.Forms.Core/TableModel.cs b/Xamarin.Forms.Core/TableModel.cs index 795a0697bdf..f99191e0e49 100644 --- a/Xamarin.Forms.Core/TableModel.cs +++ b/Xamarin.Forms.Core/TableModel.cs @@ -38,6 +38,11 @@ public virtual string GetSectionTitle(int section) return null; } + public virtual Color GetSectionTextColor(int section) + { + return Color.Default; + } + public event EventHandler> ItemLongPressed; public event EventHandler> ItemSelected; diff --git a/Xamarin.Forms.Core/TableSectionBase.cs b/Xamarin.Forms.Core/TableSectionBase.cs index 9cfa5351fd3..b384da22cf9 100644 --- a/Xamarin.Forms.Core/TableSectionBase.cs +++ b/Xamarin.Forms.Core/TableSectionBase.cs @@ -5,6 +5,7 @@ namespace Xamarin.Forms public abstract class TableSectionBase : BindableObject { public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(TableSectionBase), null); + public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TableSectionBase), Color.Default); /// /// Constructs a Section without an empty header. @@ -29,5 +30,11 @@ public string Title get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } + + public Color TextColor + { + get { return (Color)GetValue(TextColorProperty); } + set { SetValue(TextColorProperty, value); } + } } } \ No newline at end of file diff --git a/Xamarin.Forms.Core/TableView.cs b/Xamarin.Forms.Core/TableView.cs index 487e8f5fd2b..3547dcd0695 100644 --- a/Xamarin.Forms.Core/TableView.cs +++ b/Xamarin.Forms.Core/TableView.cs @@ -204,6 +204,11 @@ public override string GetSectionTitle(int section) return _root[section].Title; } + public override Color GetSectionTextColor(int section) + { + return _root[section].TextColor; + } + protected override void OnRowSelected(object item) { base.OnRowSelected(item); diff --git a/Xamarin.Forms.CustomAttributes/TestAttributes.cs b/Xamarin.Forms.CustomAttributes/TestAttributes.cs index 174f0e69270..a9df6e4878c 100644 --- a/Xamarin.Forms.CustomAttributes/TestAttributes.cs +++ b/Xamarin.Forms.CustomAttributes/TestAttributes.cs @@ -440,6 +440,7 @@ public enum TableView Intent, RowHeight, HasUnevenRows, + TableSection } public enum TableSectionBase diff --git a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs index b5c49a16cd4..34136aa02d0 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs @@ -217,13 +217,14 @@ void FillCache() for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) { var sectionTitle = model.GetSectionTitle(sectionIndex); + var sectionTextColor = model.GetSectionTextColor(sectionIndex); var sectionRowCount = model.GetRowCount(sectionIndex); if (!string.IsNullOrEmpty(sectionTitle)) { Cell headerCell = model.GetHeaderCell(sectionIndex); if (headerCell == null) - headerCell = new TextCell { Text = sectionTitle }; + headerCell = new TextCell { Text = sectionTitle, TextColor = sectionTextColor }; headerCell.Parent = _view; newIsHeaderCache.Add(true); diff --git a/Xamarin.Forms.Platform.GTK/Controls/TableView.cs b/Xamarin.Forms.Platform.GTK/Controls/TableView.cs index 3fcc1c6a44c..5d68176f7e9 100644 --- a/Xamarin.Forms.Platform.GTK/Controls/TableView.cs +++ b/Xamarin.Forms.Platform.GTK/Controls/TableView.cs @@ -142,7 +142,8 @@ void RefreshSource(TableRoot source) var tableSectionSpan = new Span() { FontSize = 12, - Text = tableSection.Title ?? string.Empty + Text = tableSection.Title ?? string.Empty, + TextColor = tableSection.TextColor }; // Table Section Title diff --git a/Xamarin.Forms.Platform.Tizen/Native/TableView.cs b/Xamarin.Forms.Platform.Tizen/Native/TableView.cs index 9b6274db2dd..8fbd4b775ae 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/TableView.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/TableView.cs @@ -13,7 +13,8 @@ public class TableView : ListView /// Initializes a new instance of the TableView class. /// public TableView(EvasObject parent) - : base(parent) { + : base(parent) + { } /// @@ -25,8 +26,8 @@ public void ApplyTableRoot(TableRoot root) Clear(); foreach (TableSection ts in root) { - if(!string.IsNullOrEmpty(ts.Title)) - AddSectionTitle(ts.Title); + if (!string.IsNullOrEmpty(ts.Title)) + AddSectionTitle(ts.Title, ts.TextColor); AddSource(ts); } } @@ -43,11 +44,12 @@ protected override CellRenderer GetCellRenderer(Cell cell, bool isGroup = false) /// /// Sets the section title. /// - void AddSectionTitle(string title) + void AddSectionTitle(string title, Color textColor) { Cell cell = new SectionCell() { - Text = title + Text = title, + TextColor = textColor }; AddCell(cell); } diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml index 3f76479799d..e01a04b1dce 100644 --- a/Xamarin.Forms.Platform.UAP/Resources.xaml +++ b/Xamarin.Forms.Platform.UAP/Resources.xaml @@ -26,7 +26,7 @@ - + @@ -97,7 +97,7 @@ - + diff --git a/Xamarin.Forms.Platform.WPF/Renderers/TableViewRenderer.cs b/Xamarin.Forms.Platform.WPF/Renderers/TableViewRenderer.cs index 50118743745..e7046d368e3 100644 --- a/Xamarin.Forms.Platform.WPF/Renderers/TableViewRenderer.cs +++ b/Xamarin.Forms.Platform.WPF/Renderers/TableViewRenderer.cs @@ -94,7 +94,7 @@ public IList GetTableViewRow() foreach (var item in Element.Root) { if (!string.IsNullOrWhiteSpace(item.Title)) - result.Add(item.Title); + result.Add(item); result.AddRange(item); } diff --git a/Xamarin.Forms.Platform.WPF/WPFResources.xaml b/Xamarin.Forms.Platform.WPF/WPFResources.xaml index bedaf7037d2..1d540afe684 100644 --- a/Xamarin.Forms.Platform.WPF/WPFResources.xaml +++ b/Xamarin.Forms.Platform.WPF/WPFResources.xaml @@ -290,8 +290,15 @@ - + + + + + + + + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs index 4a9ae081e33..e0398813712 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs @@ -63,6 +63,19 @@ public override UIView GetViewForHeader(UITableView tableView, nint section) return null; } + public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section) + { + if (headerView is UITableViewHeaderFooterView header) + { + var sectionHeaderTextColor = View.Model.GetSectionTextColor((int)section); + + if (sectionHeaderTextColor != Color.Default) + { + header.TextLabel.TextColor = sectionHeaderTextColor.ToUIColor(); + } + } + } + public void LongPress(UILongPressGestureRecognizer gesture) { var point = gesture.LocationInView(Table);