Skip to content

Commit 9e8447a

Browse files
[XSG] resolve xRefs through listnodes (#32028)
x:Reference optimization for XSG wasn't able to walk up the tree when a node is a ListNode - fixes #31995
1 parent 4e013c0 commit 9e8447a

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

src/Controls/src/SourceGen/KnownMarkups.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ internal static bool ProvideValueForReferenceExtension(ElementNode markupNode, S
480480
value = $"{namescope.namesInScope[name!].Name}";
481481
return true;
482482
}
483-
node = node.Parent as ElementNode;
483+
INode n = node;
484+
while (n.Parent is ListNode ln)
485+
n = ln.Parent;
486+
node = n.Parent as ElementNode;
484487
}
485488

486489
//TODO report diagnostic
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Issues.Maui31995"
5+
Title="Maui31995"
6+
x:Name="thisControl24">
7+
<VerticalStackLayout BindableLayout.ItemsSource="{Binding ItemsSource, Source={x:Reference thisControl24}}">
8+
<BindableLayout.ItemTemplate>
9+
<DataTemplate>
10+
<Grid>
11+
<Grid.Triggers>
12+
<DataTrigger TargetType="Grid" Binding="{Binding Selected}" Value="False">
13+
<Setter Property="VisualStateManager.VisualStateGroups">
14+
<VisualStateGroupList>
15+
<VisualStateGroup Name="CommonStates">
16+
<VisualState Name="Normal">
17+
<VisualState.Setters>
18+
<Setter Property="BackgroundColor" Value="{Binding BackgroundColor, Source={x:Reference thisControl24}}"/>
19+
</VisualState.Setters>
20+
</VisualState>
21+
<VisualState Name="PointerOver">
22+
<VisualState.Setters>
23+
<Setter Property="BackgroundColor" Value="{Binding BackgroundColor, Source={x:Reference thisControl24}}"/>
24+
</VisualState.Setters>
25+
</VisualState>
26+
</VisualStateGroup>
27+
</VisualStateGroupList>
28+
</Setter>
29+
</DataTrigger>
30+
<DataTrigger TargetType="Grid" Binding="{Binding Selected}" Value="True">
31+
<Setter Property="VisualStateManager.VisualStateGroups">
32+
<VisualStateGroupList>
33+
<VisualStateGroup Name="CommonStates">
34+
<VisualState Name="Normal">
35+
<VisualState.Setters>
36+
<Setter Property="BackgroundColor" Value="{Binding BackgroundColor, Source={x:Reference thisControl24}}"/>
37+
</VisualState.Setters>
38+
</VisualState>
39+
</VisualStateGroup>
40+
</VisualStateGroupList>
41+
</Setter>
42+
</DataTrigger>
43+
</Grid.Triggers>
44+
<Label Text="{Binding .}" />
45+
46+
</Grid>
47+
</DataTemplate>
48+
</BindableLayout.ItemTemplate>
49+
</VerticalStackLayout>
50+
</ContentPage>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
namespace Microsoft.Maui.Controls.Xaml.UnitTests.Issues;
4+
#nullable enable
5+
6+
public partial class Maui31995 : ContentPage
7+
{
8+
public Maui31995() => InitializeComponent();
9+
10+
int count = 0;
11+
public List<object> ItemsSource = new(); // Added.
12+
13+
14+
15+
private void OnCounterClicked(object? sender, EventArgs e)
16+
{
17+
count++;
18+
}
19+
}

0 commit comments

Comments
 (0)