Hi all
I have a UserControl with a DependencyProperty. I set it's value in the host window using a data binding expression. However, it doesn't work as expected.
Snippet from the user control's codebehind:
public class ViewBase : UserControl
{
public static readonly DependencyProperty ViewModelProperty
= DependencyProperty.Register(
"ViewModel", typeof(ViewModelBase), typeof(ViewBase));
public ViewModelBase ViewModel
{
get { return GetValue(ViewModelProperty) as ViewModelBase; }
set
{
SetValue(ViewModelProperty, value);
}
}
}
And from the XAML (note: CasingListView inherits from ViewBase):
<CasingEditor:CasingListView x:Name="_casingListView"
ViewModel="{Binding CasingListViewModel}" />
What happens is nothing. Specifically, the setter is never called, and the property remains null. I know the source property CasingListViewModel
has a value, because I have tried to bind it to another property (DataContext), and it worked fine.
I thought a dependency property could be databound. Am I wrong?