diff --git a/src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs b/src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs index c317792fc397..3ba35e8739b0 100644 --- a/src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs +++ b/src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs @@ -76,57 +76,57 @@ public void Visit(ElementNode node, INode parentNode) } //`` elements - if (node.XmlType.Name == "OnPlatform" && node.XmlType.NamespaceUri == XamlParser.MauiUri) - { - var onNode = GetOnNode(node, Target) ?? GetDefault(node); - - //Property node - if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out XmlName name) - && parentNode is IElementNode parentEnode) - { - if (onNode != null) - parentEnode.Properties[name] = onNode; - else - parentEnode.Properties.Remove(name); - return; - } - - //Collection item - if (onNode != null && parentNode is IElementNode parentEnode2) - parentEnode2.CollectionItems[parentEnode2.CollectionItems.IndexOf(node)] = onNode; - - } - - INode GetOnNode(ElementNode onPlatform, string target) - { - foreach (var onNode in onPlatform.CollectionItems) - { - if ((onNode as ElementNode).Properties.TryGetValue(new XmlName("", "Platform"), out var platform)) - { - var splits = ((platform as ValueNode).Value as string).Split(','); - foreach (var split in splits) - { - if (string.IsNullOrWhiteSpace(split)) - continue; - if (split.Trim() == target) - { - if ((onNode as ElementNode).Properties.TryGetValue(new XmlName("", "Value"), out var node)) - return node; - - return (onNode as ElementNode).CollectionItems.FirstOrDefault(); - } - } - } - } - return null; - } - - INode GetDefault(ElementNode onPlatform) - { - if (node.Properties.TryGetValue(new XmlName("", "Default"), out INode defaultNode)) - return defaultNode; - return null; - } + //if (node.XmlType.Name == "OnPlatform" && node.XmlType.NamespaceUri == XamlParser.MauiUri) + //{ + // var onNode = GetOnNode(node, Target) ?? GetDefault(node); + + // //Property node + // if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out XmlName name) + // && parentNode is IElementNode parentEnode) + // { + // if (onNode != null) + // parentEnode.Properties[name] = onNode; + // else + // parentEnode.Properties.Remove(name); + // return; + // } + + // //Collection item + // if (onNode != null && parentNode is IElementNode parentEnode2) + // parentEnode2.CollectionItems[parentEnode2.CollectionItems.IndexOf(node)] = onNode; + + //} + + //INode GetOnNode(ElementNode onPlatform, string target) + //{ + // foreach (var onNode in onPlatform.CollectionItems) + // { + // if ((onNode as ElementNode).Properties.TryGetValue(new XmlName("", "Platform"), out var platform)) + // { + // var splits = ((platform as ValueNode).Value as string).Split(','); + // foreach (var split in splits) + // { + // if (string.IsNullOrWhiteSpace(split)) + // continue; + // if (split.Trim() == target) + // { + // if ((onNode as ElementNode).Properties.TryGetValue(new XmlName("", "Value"), out var node)) + // return node; + + // return (onNode as ElementNode).CollectionItems.FirstOrDefault(); + // } + // } + // } + // } + // return null; + //} + + //INode GetDefault(ElementNode onPlatform) + //{ + // if (node.Properties.TryGetValue(new XmlName("", "Default"), out INode defaultNode)) + // return defaultNode; + // return null; + //} } diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml new file mode 100644 index 000000000000..559c2f208f9d --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml.cs new file mode 100644 index 000000000000..283ead115ecf --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui17461.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +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.Graphics; +using NUnit.Framework; + +namespace Microsoft.Maui.Controls.Xaml.UnitTests; + +public partial class Maui17461 : ContentPage +{ + + public Maui17461() => InitializeComponent(); + + public Maui17461(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 MissingKeyException([Values("net7.0-ios", "net7.0-android", "net7.0-macos")] string targetFramework) + { + MockCompiler.Compile(typeof(Maui17461), out var methodDef, targetFramework: targetFramework); + } + } +} \ No newline at end of file