Reputation: 6336
I have a ViewModel with 2 properties:
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?
Upvotes: 0
Views: 1480
Reputation: 184516
Under the assumption that the above binding targets the current item this should be equivalent:
{Binding SomeCollectionViewSource.View/Date}
Also see the references for Binding.Path
and 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:
{Binding Path=/Date}
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...
{Binding Date} binds to: CurrentItem -> Date
{Binding Count} binds to: Count
For clarity i would suggest always explicity writing the slash.
(Setting any DataContext
to {Binding}
is really pointless by the way)
Upvotes: 1