icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
949 stars 251 forks source link

Error when parsing XAML with a line in it #56

Closed JoshWobbles closed 5 years ago

JoshWobbles commented 5 years ago

I get an error when trying to parse the XAML this creates when I have a line in the markup. Path, rectangle etc all seem fine, but as soon as I draw a line it throws the following error:

System.Xaml.XamlObjectWriterException HResult=0x80131500 Message=Set property 'System.Windows.FrameworkElement.Margin' threw an exception. Source=System.Xaml StackTrace: at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, > Object value) Inner Exception 1: ArgumentException: 'Auto,Auto,0,0' is not a valid value for property 'Margin'.

For reference, the code I am using to parse the XAML is:

        var sb = new StringBuilder();
        using (var xmlWriter = new XamlXmlWriter(sb))
        {
            designSurface.SaveDesigner(xmlWriter);
        }
        var xamlCode = sb.ToString();

        UIElement rootElement;
        rootElement = (UIElement)XamlReader.Parse(xamlCode);
jogibear9988 commented 5 years ago

what is your xaml?

JoshWobbles commented 5 years ago

Here is the string:

<?xml version="1.0" encoding="utf-16"?><Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="rootElement"><Line Stroke="Black" StrokeThickness="2" Stretch="None" X1="0" Y1="0" X2="140" Y2="75" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="Auto,Auto,0,0" /></Grid>

Other than the grid element which is there by default, the only thing I do is draw a single line. Also to reiterate, no other control seems to do this.