-
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.
[X] Process ContentProperty before Add()
We added IEnumerable interface, and Add() methods, to Layouts in MAUI. As the XAML inflaters were trying to Add() before looking for a ContentProperty, 1/ ContentProperty on Layout (like Grid) is completely ignored (but layouts works nonetheless, because of belt and suspenders). 2/ overriding the ContentProperty is ignored (as found in #6944) This PR changes the order of Add() and ContentProperty processing, and restore the expected behavior, without breaking any other unit test. - fixes #6944
- Loading branch information
1 parent
2a7acdc
commit f1d55ed
Showing
4 changed files
with
91 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?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.Maui6944"> | ||
<local:Maui6944Layout x:Name="layout"> | ||
<Label x:Name="label"/> | ||
</local:Maui6944Layout> | ||
</ContentPage> |
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,52 @@ | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Devices; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests | ||
{ | ||
public partial class Maui6944 : ContentPage | ||
{ | ||
public Maui6944() => InitializeComponent(); | ||
public Maui6944(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 ContentPropertyAttributeOnLayoutSubclass([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
var page = new Maui6944(useCompiledXaml); | ||
Assert.That(page.layout, Is.Not.Null); | ||
Assert.That(page.layout, Is.TypeOf<Maui6944Layout>()); | ||
Assert.That(page.layout.ChildContent, Is.EqualTo(page.label)); | ||
} | ||
} | ||
} | ||
|
||
public class Maui6944Base : Grid | ||
{ | ||
} | ||
|
||
[ContentProperty("ChildContent")] | ||
public class Maui6944Layout : Maui6944Base | ||
{ | ||
public static readonly BindableProperty ChildContentProperty = | ||
BindableProperty.Create( | ||
nameof(ChildContent), | ||
typeof(View), typeof(Maui6944Layout), | ||
defaultValue: null); | ||
|
||
public View ChildContent { | ||
get => (View)GetValue(ChildContentProperty); | ||
set => SetValue(ChildContentProperty, value); | ||
} | ||
|
||
} | ||
} |