MyNewName
MyNewName

Reputation: 1055

Different DataContext in ItemsControl

My Code looks like this:

<ItemsControl ItemsSource="{Binding Path=MTMngRoot.MTManager.MTCollection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                 <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                 </Grid.ColumnDefinitions>

                <TextBox Text="{Binding Path=Name}" ToolTip="Name" Controls:TextBoxHelper.Watermark="Name" Grid.Column="0"/>
                <ComboBox SelectedItem="{Binding Path=DefaultCT}" Grid.Column="1">
                    <ComboBoxItem>Item 1</ComboBoxItem>
                    <ComboBoxItem>Item 2</ComboBoxItem>
                </ComboBox>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

This code works correctly. But now I want to bind the Itemssource from the ComboBox. My Problem is now, the Path of the Items that should be bind to the ComboBox is completly different. The Path looks like this: CTMngRoot.CTManager.CTCollection.Name. Any ideas how I can do this?

Upvotes: 0

Views: 604

Answers (1)

brunnerh
brunnerh

Reputation: 184647

You walk up to the control with the correct DataContext in these cases.

{Binding DataContext.CTMngRoot.CTManager.CTCollection,
         RelativeSource={RelativeSource AncestorType=ItemsControl}}

Upvotes: 2

Related Questions