As per the title really, how can you set a dependency property in XAML when the base class is generic? When trying to do this I get a NullReferenceException, setting the pro
My guess is that the problem lies with the owner type of the dependency property (typeof(WindowBase
As you found, the non-generic class works because the owner type and the runtime type are the same.
You can get the behaviour you want by pushing the DPs to a non-generic base but still derive your views from a generic class to get the strongly typed models
public class WindowBase : Window
{
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
"Header", typeof(string), typeof(WindowBase), new PropertyMetadata("No Header Name Assigned"));
public string Header
{
get { return (string)GetValue(HeaderProperty); }
protected set { SetValue(HeaderProperty, value); }
}
}
public class WindowBase : WindowBase
{
protected ViewModel Model { get; set; }
}