-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[X] Pass the parent scopes to DataContext
This allows correct x:Reference resolution in DataTemplates - fixes #8149
- Loading branch information
1 parent
5fbfc26
commit 0ff6984
Showing
17 changed files
with
204 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui8149" | ||
x:Name="Self"> | ||
|
||
<local:Maui8149View> | ||
<local:Maui8149View.ItemTemplate> | ||
<DataTemplate> | ||
<local:Maui8149Item> | ||
<Label x:Name="label" Text="{Binding Source={x:Reference Self}}"/> | ||
</local:Maui8149Item> | ||
</DataTemplate> | ||
</local:Maui8149View.ItemTemplate> | ||
</local:Maui8149View> | ||
|
||
</ContentView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Controls.Shapes; | ||
using Microsoft.Maui.Devices; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui8149 : ContentView | ||
{ | ||
|
||
public Maui8149() => InitializeComponent(); | ||
|
||
public Maui8149(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
class Test | ||
{ | ||
[SetUp] public void Setup() => AppInfo.SetCurrent(new MockAppInfo()); | ||
[TearDown] public void TearDown() => AppInfo.SetCurrent(null); | ||
|
||
[Test] | ||
public void NamescopeWithXamlC([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
if (useCompiledXaml) | ||
MockCompiler.Compile(typeof(Maui8149)); | ||
|
||
var page = new Maui8149(useCompiledXaml); | ||
Assert.That((page.Content as Maui8149View).Text, Is.EqualTo("Microsoft.Maui.Controls.Xaml.UnitTests.Maui8149")); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Controls/tests/Xaml.UnitTests/Issues/Maui8149Item.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui8149Item" | ||
x:Name="Self"> | ||
|
||
<!-- | ||
Note the 'x:Name="Self" | ||
In this *minimal* repro, all Content is provided by the DataTemplate | ||
--> | ||
|
||
</ContentView> |
9 changes: 9 additions & 0 deletions
9
src/Controls/tests/Xaml.UnitTests/Issues/Maui8149Item.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui8149Item : ContentView | ||
{ | ||
public Maui8149Item() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Controls/tests/Xaml.UnitTests/Issues/Maui8149View.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui8149View" | ||
x:Name="Self"> | ||
|
||
|
||
|
||
</ContentView> |
20 changes: 20 additions & 0 deletions
20
src/Controls/tests/Xaml.UnitTests/Issues/Maui8149View.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui8149View : ContentView | ||
{ | ||
private Controls.DataTemplate _itemTemplate; | ||
public string Text { get; set; } | ||
public Microsoft.Maui.Controls.DataTemplate ItemTemplate { | ||
get => _itemTemplate; | ||
set { | ||
_itemTemplate = value; | ||
Content = _itemTemplate.CreateContent() as View; | ||
Text = ((Content as Maui8149Item).Content as Label).Text; | ||
} | ||
} | ||
|
||
public Maui8149View() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |