I'm Trying to load the following basic xaml with XamlObjectWriter (.Net 4) (source code included)
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525" x:Name="mainWindow">
The code is quite simple:
XmlReader xr = XmlReader.Create("../../XAMLSimpl.xaml");
XamlXmlReader reader = new XamlXmlReader(xr);
XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext);
while (reader.Read())
{
writer.WriteNode(reader);
}
object res = writer.Result;
When I run the the code I get the following exception (because the binding)
{"A 'Binding' cannot be set on the 'Content' property of type 'Button'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject."}
A 'Binding' cannot be set on the 'Content' property of type 'Button'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
If I try to use the old style code:
FileStream reader = new FileStream("../../XAMLSimpl.xaml", FileMode.Open);
object res = System.Windows.Markup.XamlReader.Load(reader);
Everything works fine.
Any suggestion?
Many thanks in advance,
Edu.
Replies
Know the answer? Post it — somebody with the same question will find it here.