-
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] Fix TargetType simplification bug (#21764)
* Add unit test * Simplify TargetType=x:Type before setting resources
- Loading branch information
1 parent
5d33bf3
commit df8aa54
Showing
4 changed files
with
75 additions
and
3 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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui21757"> | ||
<Color x:Key="Gray-200">#C8C8C8</Color> | ||
<Style x:Key="A" TargetType="BoxView"> | ||
<Setter Property="Color" Value="{StaticResource Gray-200}" /> | ||
</Style> | ||
<Style x:Key="B" TargetType="{x:Type BoxView}"> | ||
<Setter Property="Color" Value="{StaticResource Gray-200}" /> | ||
</Style> | ||
</ResourceDictionary> |
60 changes: 60 additions & 0 deletions
60
src/Controls/tests/Xaml.UnitTests/Issues/Maui21757.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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Controls.Shapes; | ||
using Microsoft.Maui.Devices; | ||
using Microsoft.Maui.Dispatching; | ||
|
||
using Microsoft.Maui.Graphics; | ||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui21757 | ||
{ | ||
public Maui21757() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Maui21757(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 TypeLiteralAndXTypeCanBeUsedInterchangeably([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
var resourceDictionary = new Maui21757(useCompiledXaml); | ||
|
||
var styleA = resourceDictionary["A"] as Style; | ||
Assert.NotNull(styleA); | ||
Assert.That(styleA.TargetType, Is.EqualTo(typeof(BoxView))); | ||
Assert.That(styleA.Setters[0].Property, Is.EqualTo(BoxView.ColorProperty)); | ||
Assert.That(styleA.Setters[0].Value, Is.EqualTo(Color.FromArgb("#C8C8C8"))); | ||
|
||
var styleB = resourceDictionary["B"] as Style; | ||
Assert.NotNull(styleB); | ||
Assert.That(styleB.TargetType, Is.EqualTo(typeof(BoxView))); | ||
Assert.That(styleB.Setters[0].Property, Is.EqualTo(BoxView.ColorProperty)); | ||
Assert.That(styleB.Setters[0].Value, Is.EqualTo(Color.FromArgb("#C8C8C8"))); | ||
} | ||
} | ||
} |