Binding UserControl to a NULL DataContext
- by user634981
I have a UserControl and am binding its DataContext to an object. I also bind the IsEnabled property of the UserControl to a boolean property of that object eg:
<my:MyUserControl DataContext="{Binding Items.SelectedItem}" IsEnabled="{Binding Path=IsEditable}"/>
This works fine provided Items.SelectedItem is not null. However, if it is null (which can happen sometimes if the Items collection is empty), the IsEnabled binding does not get evaluated and is set to true, which is not the desired behaviour.
I've tried using a MultiBinding but without success because I don't know if it's possible to bind to the DataContext. I've also tried using a DataTrigger, but again without success.
Would somebody kindly point me in the right direction as to the correct way I should be doing this.
Thanks!