Fabio L. Fabio L. - 1 year ago 165
Vb.net Question

XamlReader parse read only dependency property

I've a string containing a XAML layout of a Grid containing a UserControl.

The UserControl has a read only DependencyProperty called Code.

I would like to use XamlReader.Parse to deserialize the string in order to get the Grid and its child, but I get a System.Windows.Markup.XamlParseException because the property "Code" has been registered as read only and it can't be modified without an authorization key.

Is there another way to do it?

mm8 mm8
Answer Source

You can't set a read-only dependency property in XAML like this:

<local:MyUserControl Code="1" />

If you want to be able to do this, the dependency property should not be defined as read-only. This makes no sense.

The above XAML snippet creates an instance of MyUserControl and tries to set the Code property to "1" and obviously this won't work if Code is read-only. You won't even be able to compile this XAML so this is not really related to XamlReader.Parse.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download