Skip to content

Commit f83613f

Browse files
committed
fix: RegisterName in NameScope when entering the visual tree and fix ElementName bindings
1 parent 81e55a4 commit f83613f

File tree

45 files changed

+497
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+497
-121
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Grid.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public async Task When_Grid_Uses_Both_Syntaxes()
1515
{
1616
ExpectedDiagnostics =
1717
{
18-
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs(105,5): error CS1912: Duplicate initialization of member 'ColumnDefinitions'
19-
DiagnosticResult.CompilerError("CS1912").WithSpan(Path.Combine("Uno.UI.SourceGenerators","Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator","Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs"), 113, 5, 113, 22).WithArguments("ColumnDefinitions"),
20-
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs(139,5): error CS1912: Duplicate initialization of member 'RowDefinitions'
21-
DiagnosticResult.CompilerError("CS1912").WithSpan(Path.Combine("Uno.UI.SourceGenerators","Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator","Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs"), 147, 5, 147, 19).WithArguments("RowDefinitions"),
18+
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs(120,5): error CS1912: Duplicate initialization of member 'ColumnDefinitions'
19+
DiagnosticResult.CompilerError("CS1912").WithSpan(Path.Combine("Uno.UI.SourceGenerators","Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator","Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs"), 120, 5, 120, 22).WithArguments("ColumnDefinitions"),
20+
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs(154,5): error CS1912: Duplicate initialization of member 'RowDefinitions'
21+
DiagnosticResult.CompilerError("CS1912").WithSpan(Path.Combine("Uno.UI.SourceGenerators","Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator","Grid_Uses_Both_Syntaxes_794c1760299b374d12fe38ba3b633206.cs"), 154, 5, 154, 19).WithArguments("RowDefinitions"),
2222
},
2323
};
2424

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MvvmGeneratedMembers.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ public void MyBindBack(string s) { }
154154
}.AddGeneratedSources();
155155
test.ExpectedDiagnostics.AddRange(new[]
156156
{
157-
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(75,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
158-
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 72, 239, 72, 243).WithArguments("TestRepro.MyViewModel", "Name"),
159-
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(97,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
160-
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 94, 239, 94, 243).WithArguments("TestRepro.MyViewModel", "Name"),
161-
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(119,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
162-
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 116, 239, 116, 243).WithArguments("TestRepro.MyViewModel", "Name"),
157+
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(79,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
158+
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 79, 239, 79, 243).WithArguments("TestRepro.MyViewModel", "Name"),
159+
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(101,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
160+
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 101, 239, 101, 243).WithArguments("TestRepro.MyViewModel", "Name"),
161+
// Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs(123,239): error CS1061: 'MyViewModel' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
162+
DiagnosticResult.CompilerError("CS1061").WithSpan(@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_d6cd66944958ced0c513e0a04797b51d.cs", 123, 239, 123, 243).WithArguments("TestRepro.MyViewModel", "Name"),
163163
});
164164

165165
await test.RunAsync();

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SBUIIOFFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4343
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4444
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4545
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
46-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
46+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4747
private void InitializeComponent()
4848
{
4949
var __resourceLocator = new global::System.Uri("file:///C:/Project/0/MainPage.xaml");
@@ -52,7 +52,14 @@ private void InitializeComponent()
5252
global::Microsoft.UI.Xaml.Application.LoadComponent(this, __resourceLocator);
5353
return;
5454
}
55-
NameScope.SetNameScope(this, __nameScope);
55+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
56+
{
57+
__nameScope = existingRootNameScope;
58+
}
59+
else
60+
{
61+
NameScope.SetNameScope(this, __nameScope);
62+
}
5663
var __that = this;
5764
base.IsParsing = true;
5865
// Source 0\MainPage.xaml (Line 1:2)

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+13-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4343
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4444
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4545
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
46-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
46+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4747
private void InitializeComponent()
4848
{
4949
var __resourceLocator = new global::System.Uri("file:///C:/Project/0/MainPage.xaml");
@@ -52,7 +52,14 @@ private void InitializeComponent()
5252
global::Microsoft.UI.Xaml.Application.LoadComponent(this, __resourceLocator);
5353
return;
5454
}
55-
NameScope.SetNameScope(this, __nameScope);
55+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
56+
{
57+
__nameScope = existingRootNameScope;
58+
}
59+
else
60+
{
61+
NameScope.SetNameScope(this, __nameScope);
62+
}
5663
var __that = this;
5764
base.IsParsing = true;
5865
Resources[
@@ -322,7 +329,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 :
322329
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
323330
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
324331
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
325-
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
332+
global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
326333
public _View Build(object __ResourceOwner_1)
327334
{
328335
_View __rootInstance = null;
@@ -392,7 +399,7 @@ public _View Build(object __ResourceOwner_1)
392399
if (global::Microsoft.UI.Xaml.NameScope.GetNameScope(d) == null)
393400
{
394401
global::Microsoft.UI.Xaml.NameScope.SetNameScope(d, __nameScope);
395-
__nameScope.Owner = d;
402+
((global::Microsoft.UI.Xaml.NameScope)__nameScope).Owner = d;
396403
}
397404
global::Uno.UI.FrameworkElementHelper.AddObjectReference(d, this);
398405
}
@@ -423,7 +430,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1 :
423430
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
424431
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
425432
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
426-
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
433+
global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
427434
public _View Build(object __ResourceOwner_1)
428435
{
429436
_View __rootInstance = null;
@@ -447,7 +454,7 @@ public _View Build(object __ResourceOwner_1)
447454
if (global::Microsoft.UI.Xaml.NameScope.GetNameScope(d) == null)
448455
{
449456
global::Microsoft.UI.Xaml.NameScope.SetNameScope(d, __nameScope);
450-
__nameScope.Owner = d;
457+
((global::Microsoft.UI.Xaml.NameScope)__nameScope).Owner = d;
451458
}
452459
global::Uno.UI.FrameworkElementHelper.AddObjectReference(d, this);
453460
}

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4343
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4444
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4545
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
46-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
46+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4747
private void InitializeComponent()
4848
{
4949
var __resourceLocator = new global::System.Uri("file:///C:/Project/0/MainPage.xaml");
@@ -52,7 +52,14 @@ private void InitializeComponent()
5252
global::Microsoft.UI.Xaml.Application.LoadComponent(this, __resourceLocator);
5353
return;
5454
}
55-
NameScope.SetNameScope(this, __nameScope);
55+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
56+
{
57+
__nameScope = existingRootNameScope;
58+
}
59+
else
60+
{
61+
NameScope.SetNameScope(this, __nameScope);
62+
}
5663
var __that = this;
5764
base.IsParsing = true;
5865
Resources[
@@ -177,7 +184,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 :
177184
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
178185
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
179186
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
180-
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
187+
global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
181188
public _View Build(object __ResourceOwner_1)
182189
{
183190
_View __rootInstance = null;
@@ -247,7 +254,7 @@ public _View Build(object __ResourceOwner_1)
247254
if (global::Microsoft.UI.Xaml.NameScope.GetNameScope(d) == null)
248255
{
249256
global::Microsoft.UI.Xaml.NameScope.SetNameScope(d, __nameScope);
250-
__nameScope.Owner = d;
257+
((global::Microsoft.UI.Xaml.NameScope)__nameScope).Owner = d;
251258
}
252259
global::Uno.UI.FrameworkElementHelper.AddObjectReference(d, this);
253260
}

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLS/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4343
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4444
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4545
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
46-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
46+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4747
private void InitializeComponent()
4848
{
4949
var __resourceLocator = new global::System.Uri("file:///C:/Project/0/MainPage.xaml");
@@ -52,7 +52,14 @@ private void InitializeComponent()
5252
global::Microsoft.UI.Xaml.Application.LoadComponent(this, __resourceLocator);
5353
return;
5454
}
55-
NameScope.SetNameScope(this, __nameScope);
55+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
56+
{
57+
__nameScope = existingRootNameScope;
58+
}
59+
else
60+
{
61+
NameScope.SetNameScope(this, __nameScope);
62+
}
5663
var __that = this;
5764
base.IsParsing = true;
5865
Resources[

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFRT/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4343
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4444
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4545
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
46-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
46+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4747
private void InitializeComponent()
4848
{
4949
var __resourceLocator = new global::System.Uri("file:///C:/Project/0/MainPage.xaml");
@@ -52,7 +52,14 @@ private void InitializeComponent()
5252
global::Microsoft.UI.Xaml.Application.LoadComponent(this, __resourceLocator);
5353
return;
5454
}
55-
NameScope.SetNameScope(this, __nameScope);
55+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
56+
{
57+
__nameScope = existingRootNameScope;
58+
}
59+
else
60+
{
61+
NameScope.SetNameScope(this, __nameScope);
62+
}
5663
var __that = this;
5764
base.IsParsing = true;
5865
Resources[

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFTLRD/XamlCodeGenerator_MyDictionary_b7707bcf1e73425b710b6a5d04177088.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public sealed partial class GlobalStaticResources
6262
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
6363
internal sealed class ResourceDictionarySingleton__MyDictionary_b7707bcf1e73425b710b6a5d04177088 : global::Uno.UI.IXamlResourceDictionaryProvider
6464
{
65-
private static global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
65+
private static global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
6666
private static global::Uno.UI.IXamlResourceDictionaryProvider __that;
6767
internal static global::Uno.UI.IXamlResourceDictionaryProvider Instance
6868
{

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TAA/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4040
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4141
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4242
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
43-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
43+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4444
private void InitializeComponent()
4545
{
46-
NameScope.SetNameScope(this, __nameScope);
46+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
47+
{
48+
__nameScope = existingRootNameScope;
49+
}
50+
else
51+
{
52+
NameScope.SetNameScope(this, __nameScope);
53+
}
4754
var __that = this;
4855
base.IsParsing = true;
4956
// Source 0\MainPage.xaml (Line 1:2)

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TBTNSICB/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page
4040
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
4141
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4242
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
43-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
43+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4444
private void InitializeComponent()
4545
{
46-
NameScope.SetNameScope(this, __nameScope);
46+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
47+
{
48+
__nameScope = existingRootNameScope;
49+
}
50+
else
51+
{
52+
NameScope.SetNameScope(this, __nameScope);
53+
}
4754
var __that = this;
4855
base.IsParsing = true;
4956
// Source 0\MainPage.xaml (Line 1:2)

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TBTNSICB/XamlCodeGenerator_UserControl1_81d855d5b3bba02f594dcda3b149beb2.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ partial class UserControl1 : global::Microsoft.UI.Xaml.Controls.UserControl
4040
private const string __baseUri_prefix_UserControl1_81d855d5b3bba02f594dcda3b149beb2 = "ms-appx:///TestProject/";
4141
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4242
private const string __baseUri_UserControl1_81d855d5b3bba02f594dcda3b149beb2 = "ms-appx:///TestProject/";
43-
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
43+
private global::Microsoft.UI.Xaml.Markup.INameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
4444
private void InitializeComponent()
4545
{
46-
NameScope.SetNameScope(this, __nameScope);
46+
if (NameScope.GetNameScope(this) is { } existingRootNameScope)
47+
{
48+
__nameScope = existingRootNameScope;
49+
}
50+
else
51+
{
52+
NameScope.SetNameScope(this, __nameScope);
53+
}
4754
var __that = this;
4855
base.IsParsing = true;
4956
// Source 0\UserControl1.xaml (Line 1:2)

0 commit comments

Comments
 (0)