0
votes

I have a view that has a ViewModel set as DataContext. That ViewModel has a boolean Property, call it "IsInEditMode". How do I bind from the UserControl in the DataTemplate (marked as "Binding IsInEditMode") to the ViewModel on the outside?

<ItemsControl ItemTemplate="{StaticResource HomeItemTemplate}">
    <ItemsControl.Resources>
        <DataTemplate x:Key="HomeItemTemplate">
            <utils:PersonTextBox Property="{Binding IsInEditMode}"/>
        </DataTemplate>
    </ItemsControl.Resources>
</ItemsControl>
1

1 Answers

0
votes

You can use a RelativeSource binding to get to the outer ItemsControl, and then bind to its data context:

<utils:PersonTextBox Property="{Binding 
    RelativeSource={RelativeSource AncestorType=ItemsControl},
    Path=DataContext.IsInEditMode}"/>