I have a ViewModel with 2 properties:
- IsReadOnly
- SomeCollectionViewSource
This is a simple working view example:
<StackPanel DataContext="{Binding SomeCollectionViewSource}">
<DatePicker SelectedDate="{Binding Path=Date}" IsEnabled="False" />
</StackPanel>
Now I want to bind the IsEnabled property:
<StackPanel DataContext="{Binding}">
<DatePicker SelectedDate="{Binding Path=?}" IsEnabled="{Binding IsReadOnly}" />
</StackPanel>
How should the binding look like in this example? (I think I’m mising something simple)
I would prefer a short and easy binding since I have a lot of controls to bind.
Is there a better/easier way to make all controls on one CollectionViewSource read-only?
Under the assumption that the above binding targets the current item this should be equivalent:
Also see the references for
Binding.Pathand the PropertyPath syntax if you have not read them already, there’s a lot to it.The above binding (of your two bindings) is equivalent to:
The slash can be omitted and if the property is not found on the collection the binding looks for the property on the current item. so…
For clarity i would suggest always explicity writing the slash.
(Setting any
DataContextto{Binding}is really pointless by the way)