0
votes

Okay, I have a relatively involved problem. I'm trying to create a Window in WPF. The main element on this window is a DataGrid. Each one of the rows in the DataGrid has a DetailsPane which I set using DataGrid.RowDetailsTemplate. Depending on certain row-specific values, I need the DetailsPane to display different elements. To accomplish this I placed a ContentControl at the root of the DataTemplate and used a Style with DataTriggers to set its Content property. Now, inside one of these Setters is a ComboBox. This ComboBox needs to have its ItemsSource bound to a list, which is stored in a dependency property on the Window level (because its the same list regardless of the row). Below is a simplified version of what I'm looking at:

<Window>
    ...
    <DataGrid>
        ...
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <ContentControl>
                    <Style TargetType="ContentControl">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RowSpecificBooleanProperty}" Value="False">
                                <Setter Property="Content">
                                    <Setter.Value>
                                        ...
                                        <ComboBox ItemsSource={HowDoIBindThisToTheWindowProperty}/>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl>
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
    </DataGrid>
</Window>

So what I'm trying to figure out is how to bind the ItemsSource of that ComboBox to a dependency property of the top-level window. Andy idea how to accomplish that?

EDIT:

I should have mentioned this before but I've already tried using {RelativeSource AncestorType=Window} and ElementName in the binding. In both cases the list in the ComboBox is blank at runtime.

1
RelativeSource (= Window) (stackoverflow.com/questions/84278/…) or ElementName are used in Binding usuallyASh

1 Answers

0
votes
ItemsSource="{Binding WhateverList, RelativeSource={RelativeSource AncestorType=Window}}"