I'm writing a value input control can be used everywhere. The control itself has a view model which set to its DataContext as usual. But when I use the control in a parent control like:
<UserControl x:Class="X.Y.Z.ParentControl">
...
<local:ValueInput Value="{Binding Path=MyValue}" />
...
</UserControl>
I'm going to bind the MyValue
property of ParentControl
's DataContext
to the ValueInput
control, but WPF tell me it cannot find the MyValue
property in ValueInputViewModel
class, which is the view model of ValueInput
control itself. Why WPF is looking for the value from child's DataContext
?
I just want to write a control which can be used like this:
<telerik:RadNumericUpDown Value="{Binding Path=NumberValue}" />
The NumberValue
property is defined in in the parent's DataContext
, not in the control's. This pattern works for teleriks control but not for my control.
What should I do?