I created UserControl with viewmodel. It has DependencyProperty which only works if the value is passed directly. If the value is passed through the binding, it no longer works.
There is no IsConnected
property in the SomeViewModel
instance in the current DataContext of the UserControl, hence the Binding
won't work. It tries to resolve the PropertyPath against the current DataContext, unless you explicitly specify its Source
, RelativeSource
or ElementName
.
This is the exact reason why UserControls should never explicitly set their own DataContext, and hence never have something like an own, private view model.
The elements in the UserControl's XAML would not bind to properties of such a private view model object, but directly to the properties of the UserControl, for example like