-
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.
[XC] Produce warning when x:DataType is inherited from outer scope of…
… `DataTemplate` (#22803) * Add tests * Add build exception * Detect leaving DataTemplate scope
- Loading branch information
1 parent
78eb023
commit 4ca773f
Showing
7 changed files
with
135 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui22714" | ||
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"> | ||
|
||
<StackLayout> | ||
<ScrollView x:DataType="local:PageViewModel22714"> | ||
<StackLayout BindableLayout.ItemsSource="{Binding Items}"> | ||
<BindableLayout.ItemTemplate> | ||
<DataTemplate x:DataType="local:ItemViewModel22714"> | ||
<Label Text="{Binding Title}" /> | ||
</DataTemplate> | ||
</BindableLayout.ItemTemplate> | ||
</StackLayout> | ||
</ScrollView> | ||
|
||
<ScrollView x:DataType="local:PageViewModel22714"> | ||
<StackLayout BindableLayout.ItemsSource="{Binding Items}"> | ||
<BindableLayout.ItemTemplate> | ||
<DataTemplate> | ||
<Label Text="{Binding Title}" /> | ||
</DataTemplate> | ||
</BindableLayout.ItemTemplate> | ||
</StackLayout> | ||
</ScrollView> | ||
</StackLayout> | ||
</ContentPage> |
71 changes: 71 additions & 0 deletions
71
src/Controls/tests/Xaml.UnitTests/Issues/Maui22714.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,71 @@ | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Dispatching; | ||
|
||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
[XamlCompilation(XamlCompilationOptions.Skip)] | ||
public partial class Maui22714 | ||
{ | ||
public Maui22714() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Maui22714(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
public class Test | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Application.SetCurrentApplication(new MockApplication()); | ||
DispatcherProvider.SetCurrent(new DispatcherProviderStub()); | ||
} | ||
|
||
[TearDown] public void TearDown() => AppInfo.SetCurrent(null); | ||
|
||
[Test] | ||
public void TestNonCompiledResourceDictionary( | ||
[Values(false, true)] bool useCompiledXaml, | ||
[Values(false, true)] bool treatWarningsAsErrors) | ||
{ | ||
if (useCompiledXaml) | ||
{ | ||
if (treatWarningsAsErrors) | ||
{ | ||
Assert.Throws( | ||
new BuildExceptionConstraint(22, 32, static msg => msg.Contains(" XC0024 ", System.StringComparison.Ordinal)), | ||
() => MockCompiler.Compile(typeof(Maui22714), treatWarningsAsErrors: true)); | ||
} | ||
else | ||
{ | ||
MockCompiler.Compile(typeof(Maui22714), treatWarningsAsErrors: false); | ||
} | ||
} | ||
else | ||
{ | ||
// This will never affect non-compiled builds | ||
_ = new Maui22714(useCompiledXaml); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class PageViewModel22714 | ||
{ | ||
public string Title { get; set; } | ||
public ItemViewModel22714[] Items { get; set; } | ||
} | ||
|
||
public class ItemViewModel22714 | ||
{ | ||
public string Title { get; set; } | ||
} |
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