diff --git a/components/Extensions/samples/ListViewExtensions.md b/components/Extensions/samples/ListViewExtensions.md index 682cd597..877101e3 100644 --- a/components/Extensions/samples/ListViewExtensions.md +++ b/components/Extensions/samples/ListViewExtensions.md @@ -31,14 +31,7 @@ The `AlternateColor` property provides a way to assign a background color to eve Here is how this property can be used in XAML: -```xaml - - - -``` +> [!SAMPLE ListViewExtensionsAlternateColorSample] ## AlternateItemTemplate diff --git a/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml b/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml new file mode 100644 index 00000000..46f5fc41 --- /dev/null +++ b/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml @@ -0,0 +1,21 @@ + + + + + One + Two + Three + Four + Five + Six + Seven + Eight + Nine + Ten + + + diff --git a/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml.cs b/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml.cs new file mode 100644 index 00000000..20318e11 --- /dev/null +++ b/components/Extensions/samples/ListViewExtensionsAlternateColorSample.xaml.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace ExtensionsExperiment.Samples; + +/// +/// An empty page that can be used on its own or navigated to within a Frame. +/// +[ToolkitSample(id: nameof(ListViewExtensionsAlternateColorSample), nameof(ListViewExtensionsAlternateColorSample), description: $"A sample for showing how to use the ListViewExtensions.AlternateColor attached property.")] +public sealed partial class ListViewExtensionsAlternateColorSample : Page +{ + public ListViewExtensionsAlternateColorSample() + { + this.InitializeComponent(); + } +} diff --git a/components/Extensions/src/ListViewBase/ListViewExtensions.AlternateRows.cs b/components/Extensions/src/ListViewBase/ListViewExtensions.AlternateRows.cs index 65ef5340..1e73c325 100644 --- a/components/Extensions/src/ListViewBase/ListViewExtensions.AlternateRows.cs +++ b/components/Extensions/src/ListViewBase/ListViewExtensions.AlternateRows.cs @@ -192,10 +192,20 @@ private static void SetItemContainerBackground(ListViewBase sender, Control item if (itemIndex % 2 == 0) { itemContainer.Background = GetAlternateColor(sender); + var rootBorder = itemContainer.FindDescendant(); + if (rootBorder != null) + { + rootBorder.Background = GetAlternateColor(sender); + } } else { itemContainer.Background = null; + var rootBorder = itemContainer.FindDescendant(); + if (rootBorder != null) + { + rootBorder.Background = null; + } } } }