首页 文章

在DataTemplate WPF中的样式设置器中绑定

提问于
浏览
0

好的,我有一个相对棘手的问题 . 我正在尝试在WPF中创建一个Window . 此窗口的主要元素是DataGrid . DataGrid中的每一行都有一个DetailsPane,我使用DataGrid.RowDetailsTemplate设置它 . 根据某些特定于行的值,我需要DetailsPane来显示不同的元素 . 为此,我将ContentControl放在DataTemplate的根目录下,并使用Style with DataTriggers设置其Content属性 . 现在,其中一个Setters是一个ComboBox . 这个ComboBox需要将其ItemsSource绑定到一个列表,该列表存储在Window级别的依赖项属性中(因为它与列无关,因此它是相同的列表) . 以下是我正在看的简化版本:

<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>

所以我想弄清楚的是如何将该ComboBox的ItemsSource绑定到顶级窗口的依赖属性 . 安迪想法如何实现这一目标?

EDIT:

我之前应该提到过这个,但我已经尝试在绑定中使用和ElementName . 在这两种情况下,ComboBox中的列表在运行时都是空白的 .

1 回答

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

相关问题