首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绑定到DataGridRowHeader中的集合不像预期的那样工作

绑定到DataGridRowHeader中的集合不像预期的那样工作
EN

Stack Overflow用户
提问于 2017-12-12 15:04:52
回答 1查看 36关注 0票数 0

我的DataGrid被绑定到一个ObservableCollection<Entry>

代码语言:javascript
复制
public class Entry
{
     public List<string> Types {get; set;} = new List<string>() {"Type1", "Type2"};
}

由于DataGrid.ItemsSourceEntry的集合,所以我希望单个DataGridRowDataContext是typeof(Entry)。

代码语言:javascript
复制
<DataGrid ItemsSource="{Binding Entries}">
    <DataGrid.RowHeaderTemplate>
       <DataTemplate>
          <Border Width="100">
              <StackPanel>                                
                  <ComboBox ItemsSource="{Binding DataContext.Entries[0].Types, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
                  <ComboBox ItemsSource="{Binding Types}" />
              </StackPanel>
          </Border>
      </DataTemplate>
   </DataGrid.RowHeaderTemplate>
</DataGrid>

第一个Binding是工作的,第二个是无效的。

不过,我在Visual的BindingError Output-Window中没有获得任何信息。

我需要为每个Types显示Entry,这样通过索引的访问就不能工作了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-12 15:14:54

这应该是可行的:

代码语言:javascript
复制
<ComboBox ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}}" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47775689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档