Help with Binding Expression

Topics: Conventions
Jun 22, 2011 at 4:13 PM

I have a control which is a WPF version of a DataForm, that is displaying a single customer. The control requires its DataContext set to the customer, in my case CurrentCustomer property from CustomerViewModel.

            <dv:DetailsView x:Name="SelectedCustomer" 
                             DataContext="{Binding CurrentCustomer, Mode=TwoWay}" 
                             AllowEdit="{Binding WHATDOIWRITEHERE}"

But AllowEdit should be bound to the AllowEdit property on the CustomerViewModel. Is there a binding expression I can write to do this?

The control by the way is,



Jun 22, 2011 at 4:40 PM

You could use a RelativeSource Ancestor binding to bind to the DataContext of the containing UserControl.

Jun 22, 2011 at 5:07 PM

Thanks Rob,
That was the clue I needed.
Working now with

            <dv:DetailsView x:Name="SelectedCustomer" 
                             DataContext="{Binding ., Path=CurrentCustomer, Mode=TwoWay}" 
                             AllowEdit="{Binding DataContext.AllowEdit, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"