Skip to content

Fix issue with Windows 11 ListViewStyle #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions components/Extensions/samples/ListViewExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Page ...
xmlns:ui="using:CommunityToolkit.WinUI">

<ListView
ui:ListViewExtensions.AlternateColor="Silver"
ItemsSource="{x:Bind MainViewModel.Items, Mode=OneWay}" />
```
> [!SAMPLE ListViewExtensionsAlternateColorSample]

## AlternateItemTemplate

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Page x:Class="ExtensionsExperiment.Samples.ListViewExtensionsAlternateColorSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:CommunityToolkit.WinUI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<ListView ui:ListViewExtensions.AlternateColor="Silver">
<ListView.Items>
<x:String>One</x:String>
<x:String>Two</x:String>
<x:String>Three</x:String>
<x:String>Four</x:String>
<x:String>Five</x:String>
<x:String>Six</x:String>
<x:String>Seven</x:String>
<x:String>Eight</x:String>
<x:String>Nine</x:String>
<x:String>Ten</x:String>
</ListView.Items>
</ListView>
</Page>
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,20 @@ private static void SetItemContainerBackground(ListViewBase sender, Control item
if (itemIndex % 2 == 0)
{
itemContainer.Background = GetAlternateColor(sender);
var rootBorder = itemContainer.FindDescendant<Border>();
if (rootBorder != null)
{
rootBorder.Background = GetAlternateColor(sender);
}
}
else
{
itemContainer.Background = null;
var rootBorder = itemContainer.FindDescendant<Border>();
if (rootBorder != null)
{
rootBorder.Background = null;
}
}
}
}
Loading