Reputation: 9710
I've followed the instruction from Adding custom attributes to an element in XAML? but unfortunately the designer tells me that he can't find the element and when starting the program I get an XamlParserException with the message Cannot set unknown member '{clr-namespace:myNs}MediaElementProperties.MediaId'.
My Setup:
XamlReader.Load(fileStream)
for displayingThe content page itself which uses the code like this:
<MediaElement myNs:MediaElementProperties.MediaId="test" ... />
where myNs was defined with
xmlns:myNs="clr-namespace:MyNamespace"
And the Definition of the MediaElementProperties which looks like this:
namespace MyNamespace {
public static class MediaElementProperties
{
public static readonly DependencyProperty MediaIdProperty =
DependencyProperty.Register("MediaId", typeof(string), typeof(MediaElementProperties), new FrameworkPropertyMetadata(string.Empty));
public static string GetMediaId(UIElement element)
{
return (string)element.GetValue(MediaIdProperty);
}
public static void SetMediaId(UIElement element, string value)
{
element.SetValue(MediaIdProperty, value);
}
}}
Do you have any ideas why I keep getting the exception?
Upvotes: 3
Views: 660
Reputation: 184296
Attached properties need to be registered with RegisterAttached
as noted by Zabavsky.
When using the XamlReader
you may need to be required to fully qualify your xmlns
, even though the code is in the same assembly, i.e.
xmlns:myNs="clr-namespace:MyNamespace;assembly=MyApplication"
Upvotes: 7