本文介绍了这个分组组合框绑定有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个datagridtemplate列,上面有一个分组的组合框。项目显示正确,但标题不正确,实际上显示空格。 我更改了标题字段以匹配显示的数据,标题仍然显示为空。在headertemplate中是否有一个不同于itemtemplate的绑定? Combobox绑定到一个listcollection视图,其中包含两个字段:Bienes_ID和TipoBienes_ID,并在TipoBienes_ID上进行分组。 br /> 主数据网格绑定到包含多个字段的数据视图,包括Bienes_ID。 < DataGridTemplateColumn x:名称 = ColumnaCombo > < DataGridTemplateColumn.CellTemplate > < DataTemplate > < TextBlock 文字 = {Binding Path = Bienes_ID} > < / TextBlock > < / DataTemplate > < / DataGridTemplateColumn.CellTemplate > < DataGridTemplateColumn.CellEditingTemplate > < DataTemplate > ; < ComboBox x:名称 = ComboBienesAgrupados SelectedValuePath = Bienes_ID ItemsSource = {Binding Path = Lista Bienes,RelativeSource = {RelativeSource AncestorType = Window},UpdateSourceTrigger = PropertyChanged} SelectedValue = {Binding Bienes_ID} > < ComboBox.GroupStyle > < GroupStyle > < GroupStyle.HeaderTemplate > < DataTemplate > < TextBox Text = {Binding Path = Bienes_ID} 背景 = AliceBlue > < / TextBox > < / DataTemplate > < / GroupStyle.HeaderTemplate > < / GroupStyle > < / ComboBox.GroupStyle > < ComboBox.ItemTemplate > < DataTemplate > < TextBlock 文本 = {Binding Path = Bienes_ID} > < / TextBlock > < / DataTemplate > < / ComboBox.ItemTemplate > < / ComboBox > < / DataTemplate > < / DataGridTemplateColumn.CellEditingTemplate > < / DataGridTemplateColumn > 我的尝试: 我设法在itemtemplate中显示TipoBienes_ID字段,所以只有headertemplate没有正确绑定。解决方案 显然有一个技巧,在标题中我我没有绑定数据视图中的数据对象。相反,我绑定了PropertyGroupDescription对象。因此,不必绑定到TipoBienes_ID,我必须绑定到PropertyGroupDescription.name属性,如下所示: < combobox.groupstyle > < groupstyle > < groupstyle.headertemplate > < datatemplate > < textbox text = {Binding Path = Name} background = AliceBlue > < / textbox > < / datatemplate > < / groupstyle.headertemplate > < / groupstyle > < / combobox.groupstyle > I have a datagridtemplatecolumn with a grouped combobox on it. The items are displayed correctly, but the headers are not, actually a blank space appears. I changed the Header field to match the same as the displayed data and the header still appears empty. Is there a different binding in the headertemplate than in the itemtemplate?The Combobox is binded to a listcollection view with two fields: Bienes_ID and TipoBienes_ID with grouping on TipoBienes_ID.The main datagrid is binded to a dataview with several fields, including Bienes_ID.<DataGridTemplateColumn x:Name="ColumnaCombo"> <DataGridTemplateColumn.CellTemplate > <DataTemplate > <TextBlock Text="{Binding Path=Bienes_ID}"></TextBlock> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate > <DataTemplate > <ComboBox x:Name="ComboBienesAgrupados" SelectedValuePath="Bienes_ID" ItemsSource="{Binding Path=ListaBienes, RelativeSource={RelativeSource AncestorType=Window},UpdateSourceTrigger=PropertyChanged }" SelectedValue="{Binding Bienes_ID}" > <ComboBox.GroupStyle > <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate > <TextBox Text="{Binding Path =Bienes_ID }" Background ="AliceBlue" ></TextBox> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ComboBox.GroupStyle> <ComboBox.ItemTemplate > <DataTemplate > <TextBlock Text="{Binding Path=Bienes_ID}"></TextBlock> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> </DataGridTemplateColumn>What I have tried:I managed to show in the itemtemplate the fields TipoBienes_ID, so only the headertemplate is not binding correctly. 解决方案 Apparently there is a trick, in the header I am not binding against a data object from my dataview. Instead I am binding against PropertyGroupDescription object. So instead of binding to TipoBienes_ID I had to Bind to the PropertyGroupDescription.name property like this: <combobox.groupstyle> <groupstyle> <groupstyle.headertemplate> <datatemplate> <textbox text="{Binding Path =Name}" background="AliceBlue"></textbox> </datatemplate> </groupstyle.headertemplate> </groupstyle></combobox.groupstyle> 这篇关于这个分组组合框绑定有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 15:57