Merge pull request #206 from zumero/listview-separator

Ooui.Forms ListView Separators
This commit is contained in:
Frank A. Krueger 2019-01-05 12:08:16 -06:00 committed by GitHub
commit 7d3a985e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -41,6 +41,7 @@ namespace Ooui.Forms.Renderers
e.NewElement.ScrollToRequested += ListView_ScrollToRequested; e.NewElement.ScrollToRequested += ListView_ScrollToRequested;
UpdateItems (); UpdateItems ();
UpdateSeparator ();
UpdateBackgroundColor (); UpdateBackgroundColor ();
} }
@ -53,6 +54,10 @@ namespace Ooui.Forms.Renderers
if (e.PropertyName == ItemsView<Cell>.ItemsSourceProperty.PropertyName) if (e.PropertyName == ItemsView<Cell>.ItemsSourceProperty.PropertyName)
UpdateItems (); UpdateItems ();
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorColorProperty.PropertyName)
UpdateSeparator ();
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorVisibilityProperty.PropertyName)
UpdateSeparator ();
} }
protected override void Dispose (bool disposing) protected override void Dispose (bool disposing)
@ -76,6 +81,7 @@ namespace Ooui.Forms.Renderers
private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e) private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e)
{ {
UpdateItems (); UpdateItems ();
UpdateSeparator ();
} }
private void UnsubscribeCellClicks () private void UnsubscribeCellClicks ()
@ -134,6 +140,27 @@ namespace Ooui.Forms.Renderers
} }
} }
private void UpdateSeparator()
{
if (Control == null)
return;
var listItems = Control.Children.OfType<ListItem>().ToList();
foreach (var li in listItems)
{
if (Element.SeparatorVisibility == SeparatorVisibility.Default)
{
var color = Element.SeparatorColor.ToOouiColor(Color.FromStyleValue("#999"));
li.Style["border-bottom"] = string.Format("{0}px {1} {2}", 1, "solid", color.ToString());
}
else
{
li.Style["border-bottom"] = null;
}
}
}
void ListItem_Click (object sender, TargetEventArgs e) void ListItem_Click (object sender, TargetEventArgs e)
{ {
if (Control == null) if (Control == null)