如何绑定DataGrid标题 [英] How to Bind DataGrid Header

查看:162
本文介绍了如何绑定DataGrid标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不能获得组合框 DataGridTextColumn.Header 绑定。
第一个独立组合框结合的罚款。
场仅仅是公开名单<字符串>

Cannot get the ComboBox in the DataGridTextColumn.Header to bind.
The first stand alone ComboBox binds fine.
Fields is just Public List<String>.

<StackPanel Orientation="Vertical">
    <ComboBox ItemsSource="{Binding Path=Fields}"/>
    <DataGrid ItemsSource="{Binding Path=MyRows}" AutoGenerateColumns="False" >
        <DataGrid.Columns>
            <DataGridTextColumn Width="80" Binding="{Binding Col1}">
                <DataGridTextColumn.Header>
                    <StackPanel>
                        <TextBlock Text="Header1" />
                        <ComboBox Width="60" ItemsSource="{Binding Path=Fields}" />
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>
</StackPanel>

private List<string> fields = new List<string> { "aa", "bb", "cc" };
public List<string> Fields { get { return fields; } }

甚至试图使场MyRow的房产

even tried making Fields a Property of MyRow

推荐答案

它应该工作,如果你使用的DataContext上的DataGrid中,这已继承的窗口。

It should work if you use the DataContext on the DataGrid, which has been inherited from the Window.

<ComboBox Width="60"
          ItemsSource="{Binding Path=DataContext.Fields, 
          RelativeSource={RelativeSource AncestorType=DataGrid}}" />

这篇关于如何绑定DataGrid标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆