Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML Runtime
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:
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 18-May-12 5:32am

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

  Print Answers RSS
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 162
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 18 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100