Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I seem to have a small problem getting a snippet of code to work. And just isn't a professional and would love some assistance in finding a fix!

I'm trying to at XAML at runtime, and the compiler gets an exception that says it doesn't recognize "Ellipse". I have tested the other code and works like a charm but not the runtime adding of a XAML string.

Code:
C#
private void AddTestEllipse()
{

    String xaml = "<Ellipse Height='10px' Width='10px' Fill='Yellow' Canvas.Left='0' Canvas.Top='0' Stroke='White' StrokeThickness='1' Panel.ZIndex='-800' >" +
                    "<Ellipse.RenderTransform>" +
                        "<TranslateTransform X='-8' Y='-5' />" +
                    "</Ellipse.RenderTransform>" +
                    "</Ellipse>";


    StringReader stringReader = new StringReader(xaml);
    XmlReader xmlReader = XmlReader.Create(stringReader);

    UIElement tree = (UIElement)XamlReader.Load(xmlReader);

    starfield.Children.Add(tree);
}

Exception detail:
System.Windows.Markup.XamlParseException occurred
  Message='Cannot create unknown type 'Ellipse'.' Line number '1' and line position '2'.
  Source=PresentationFramework
  LineNumber=1
  LinePosition=2
  StackTrace:
       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
       at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader)
       at StarApp.MainWindow.AddTestEllipse() in C:\Users\Frank Haugen\Documents\Visual Studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs:line 118
  InnerException: System.Xaml.XamlObjectWriterException
       Message='Cannot create unknown type 'Ellipse'.' Line number '1' and line position '2'.
       Source=System.Xaml
       LineNumber=1
       LinePosition=2
       StackTrace:
            at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
            at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
            at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
            at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       InnerException: 


Thanks!!!

-frank
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900