我有一个DataGridTemplateColumn
:
<DataGridTemplateColumn CellStyle="{x:Null}" Width="85" Header="{Extentions:DisplayName Type=Type:StandardClass, PropertyName=ProductKind}">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding ElementName=viewSourceDataGrid, Path=DataContext.ProductKindCollection}"
DisplayMemberPath="Title" Style="{x:Null}"
SelectedValue="{Binding ProductKind, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding ProductKind.Title, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
并且还尝试了:
<DataGridComboBoxColumn Header="{Extentions:DisplayName Type=Type:StandardClass, PropertyName=ProductKind}"
DisplayMemberPath="Title"
SelectedItemBinding="{Binding ProductKindID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True,ValidatesOnDataErrors=True}">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource EditBaseStyle}">
<Setter Property="ItemsSource" Value="{Binding ElementName=viewSourceDataGrid, Path=DataContext.ProductKindCollection}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource EditBaseStyle}">
<Setter Property="ItemsSource" Value="{Binding ElementName=viewSourceDataGrid, Path=DataContext.ProductKindCollection}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
在win 7上一切正常,但在win Server 2008和2003上对其进行了测试,结果:
我删除风格细胞和DataGrid但仍(正如你看到的)ComboBox
项目不出现
最终经过测试,RelativeSource
而不是ElementName
。
经过一天的时间浪费,效果很好Win Server
!
解决方案 !!:
<DataGridTemplateColumn CellStyle="{x:Null}" Width="85" Header="{Extentions:DisplayName Type=Type:StandardClass, PropertyName=ProductKind}">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding Path=DataContext.ProductKindCollection,RelativeSource={RelativeSource AncestorType=DataGrid}}"
DisplayMemberPath="Title" Style="{x:Null}"
SelectedValue="{Binding ProductKind, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding ProductKind.Title, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句