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