-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XC] Fix x:DataType resolution for BindingContext (#21454)
* Add test * Add special case for resolving x:DataType for the binding context property
- Loading branch information
1 parent
e2dd6a4
commit a7aeade
Showing
3 changed files
with
105 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Dispatching; | ||
|
||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui21434 | ||
{ | ||
public Maui21434() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Maui21434(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
class Test | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Application.SetCurrentApplication(new MockApplication()); | ||
DispatcherProvider.SetCurrent(new DispatcherProviderStub()); | ||
} | ||
|
||
[TearDown] public void TearDown() => AppInfo.SetCurrent(null); | ||
|
||
[Test] | ||
public void BindingsDoNotResolveStaticProperties([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
var page = new Maui21434(useCompiledXaml); | ||
Assert.That(page.ParentTextLabel?.Text, Is.EqualTo("ParentText")); | ||
Assert.That(page.ChildTextLabel?.Text, Is.EqualTo("ChildText")); | ||
} | ||
} | ||
} | ||
|
||
public class ParentViewModel21434 | ||
{ | ||
public string Text => "ParentText"; | ||
public ChildViewModel21434 Child { get; } = new(); | ||
} | ||
|
||
public class ChildViewModel21434 | ||
{ | ||
public string Text => "ChildText"; | ||
} |
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage 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.Maui21434" | ||
x:DataType="local:ParentViewModel21434"> | ||
<ContentPage.BindingContext> | ||
<local:ParentViewModel21434 /> | ||
</ContentPage.BindingContext> | ||
|
||
<VerticalStackLayout> | ||
<Label Text="{Binding Text}" x:Name="ParentTextLabel" /> | ||
<Label BindingContext="{Binding Child}" Text="{Binding Text}" x:DataType="local:ChildViewModel21434" x:Name="ChildTextLabel" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |