diff --git a/src/Controls/src/Build.Tasks/CompiledConverters/BindablePropertyConverter.cs b/src/Controls/src/Build.Tasks/CompiledConverters/BindablePropertyConverter.cs index 221d114ae111..0c74fe87da59 100644 --- a/src/Controls/src/Build.Tasks/CompiledConverters/BindablePropertyConverter.cs +++ b/src/Controls/src/Build.Tasks/CompiledConverters/BindablePropertyConverter.cs @@ -56,7 +56,14 @@ public FieldReference GetBindablePropertyFieldReference(string value, ILContext } } else if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == XamlParser.MauiUri && (node.Parent as ElementNode)?.XmlType.Name == nameof(Trigger)) - typeName = ((node.Parent as ElementNode).Properties[new XmlName("", "TargetType")] as ValueNode).Value as string; + { + var targetTypeNode = (node.Parent as ElementNode).Properties[new XmlName("", "TargetType")]; + if (targetTypeNode is ValueNode valueNode) + typeName = valueNode.Value as string; + else if (targetTypeNode is ElementNode elementNode && elementNode.XmlType.Name == "TypeExtension") + typeName = (elementNode.Properties[new XmlName("", "TypeName")] as ValueNode).Value as string; + + } propertyName = parts[0]; } else if (parts.Length == 2) diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml new file mode 100644 index 000000000000..308c7b95a952 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml.cs new file mode 100644 index 000000000000..f54199d0e18f --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml.cs @@ -0,0 +1,49 @@ +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 Maui18324 : ContentPage +{ + + public Maui18324() => InitializeComponent(); + + public Maui18324(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 xTypeShoudntCrash([Values(false, true)] bool useCompiledXaml) + { + if (useCompiledXaml) + MockCompiler.Compile(typeof(Maui18324)); + var page = new Maui18324(useCompiledXaml); + } + } +} \ No newline at end of file