I'm having trouble binding to a custom class. It looks like the dependency property is not getting the correct value from my viewmodel. Here is my custom class:
public class DataResource : DependencyObject { public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(DataResource)); public object Content { get { return (object)GetValue(ContentProperty); } set { SetValue(ContentProperty, value); } } }
And in my UserControl resources I have:
<UserControl.Resources> <local:DataResource x:Key="dataResource" Content="{Binding Test}"></data:DataResource> </UserControl.Resources>
The "test" in my ViewModel is a property with which I can bind a shortcut without any problems. Am I doing something wrong here in this implementation?
Update. This works if I inherit from Freezable and not DependencyObject. I'm not quite sure why, I hope someone can explain this.
source share