diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index 90b0d95ba..6a16e0482 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -908,11 +908,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection short identifier = reader.ReadInt16(); string text = reader.ReadString(); - PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); - XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); - property.Value = text; - - nodes.Enqueue(property); + EnqueueProperty(identifier, text); } void ReadPropertyWithConverter() @@ -921,11 +917,41 @@ namespace Ricciolo.StylesExplorer.MarkupReflection string text = reader.ReadString(); reader.ReadInt16(); + EnqueueProperty(identifier, text); + } + + bool HaveSeenNestedElement() + { + XmlBamlElement element = elements.Peek(); + int elementIndex = nodes.IndexOf(element); + for (int i = elementIndex + 1; i < nodes.Count; i++) + { + if (nodes[i] is XmlBamlEndElement) + return true; + } + return false; + } + + void EnqueueProperty(short identifier, string text) + { PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); - XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); - property.Value = text; - - nodes.Enqueue(property); + XmlBamlElement element = FindXmlBamlElement(); + // if we've already read a nested element for the current element, this property must be a nested element as well + if (HaveSeenNestedElement()) + { + XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Complex, pd); + + nodes.Enqueue(property); + nodes.Enqueue(new XmlBamlText(text)); + nodes.Enqueue(new XmlBamlEndElement(property)); + } + else + { + XmlBamlProperty property = new XmlBamlProperty(element, PropertyType.Value, pd); + property.Value = text; + + nodes.Enqueue(property); + } } void ReadAttributeInfo() diff --git a/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml b/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml new file mode 100644 index 000000000..becbf4713 --- /dev/null +++ b/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml @@ -0,0 +1,6 @@ +<Label xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> + <Label.Style> + <Style /> + </Label.Style> + <Label.Content>Blah</Label.Content> +</Label> \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj index ab4ec2c41..143e1ce06 100644 --- a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -133,6 +133,7 @@ </Page> <Page Include="Cases\SimpleDictionary.xaml" /> <Page Include="Cases\SimpleNames.xaml" /> + <Page Include="Cases\SimplePropertyElement.xaml" /> <Page Include="Cases\Dictionary1.xaml" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> diff --git a/ILSpy.BamlDecompiler/Tests/TestRunner.cs b/ILSpy.BamlDecompiler/Tests/TestRunner.cs index dc77434bf..59b50143d 100644 --- a/ILSpy.BamlDecompiler/Tests/TestRunner.cs +++ b/ILSpy.BamlDecompiler/Tests/TestRunner.cs @@ -73,6 +73,12 @@ namespace ILSpy.BamlDecompiler.Tests RunTest("cases/markupextension"); } + [Test] + public void SimplePropertyElement() + { + RunTest("cases/simplepropertyelement"); + } + #region RunTest void RunTest(string name) {