diff --git a/src/Controls/src/Xaml/SimplifyTypeExtensionVisitor.cs b/src/Controls/src/Xaml/SimplifyTypeExtensionVisitor.cs index 02a5139de95b..491b13c35074 100644 --- a/src/Controls/src/Xaml/SimplifyTypeExtensionVisitor.cs +++ b/src/Controls/src/Xaml/SimplifyTypeExtensionVisitor.cs @@ -55,16 +55,22 @@ static bool IsTargetTypePropertyOfMauiType(INode parentNode, XmlName propertyNam static bool IsTypeExtension(ElementNode node, out ValueNode typeNameValueNode) { - XmlName typeNameXmlName = new("", "TypeName"); - - if (node.XmlType.Name == nameof(TypeExtension) - && node.XmlType.NamespaceUri == XamlParser.X2009Uri - && node.Properties.ContainsKey(typeNameXmlName) - && node.Properties[typeNameXmlName] is ValueNode valueNode - && valueNode.Value is string) + if (node.XmlType.Name == nameof(TypeExtension) && node.XmlType.NamespaceUri == XamlParser.X2009Uri) { - typeNameValueNode = valueNode; - return true; + XmlName typeNameXmlName = new("", "TypeName"); + if (node.Properties.ContainsKey(typeNameXmlName) + && node.Properties[typeNameXmlName] is ValueNode { Value: string } propertyValueNode) + { + typeNameValueNode = propertyValueNode; + return true; + } + + if (node.CollectionItems.Count == 1 + && node.CollectionItems[0] is ValueNode { Value: string } collectionValueNode) + { + typeNameValueNode = collectionValueNode; + return true; + } } typeNameValueNode = null; diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml new file mode 100644 index 000000000000..849a660a0f38 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml.cs new file mode 100644 index 000000000000..d964e36f1b87 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui21757_2.xaml.cs @@ -0,0 +1,70 @@ +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; + +[XamlCompilation(XamlCompilationOptions.Skip)] +public partial class Maui21757_2 +{ + public Maui21757_2() + { + InitializeComponent(); + } + + public Maui21757_2(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() + { + Assert.DoesNotThrow(() => MockCompiler.Compile(typeof(Maui21757_2))); + } + } +} + +public class ViewModelMainPage21757_2 +{ + public List TestList { get; set; } + + public ViewModelMainPage21757_2() + { + TestList = new List() + { + new ViewModelTest21757_2() { TestValue = 0 }, + new ViewModelTest21757_2() { TestValue = 1 }, + new ViewModelTest21757_2() { TestValue = 2 }, + new ViewModelTest21757_2() { TestValue = 3 } + }; + } +} + +public class ViewModelTest21757_2 +{ + public int TestValue { get; set; } +} \ No newline at end of file