【问题标题】:WPF:DataGridTemplateColumn on Windows server 2003/2008WPF:Windows 服务器 2003/2008 上的 DataGridTemplateColumn
【发布时间】:2013-08-31 15:31:12
【问题描述】:

我有一个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 上进行了测试,结果:

我删除了 cell 和 DataGrid 的样式,但仍然 (如您所见)ComboBox 项目没有出现

【问题讨论】:

  • 问题是什么?
  • @Anatoliy Nikolaev:刚刚添加
  • 你在其他操作系统下测试过程序吗? (Windows XP、Windows 8)。
  • @Anatoliy Nikolaev:不,我没有,但在 2 胜 7 秒上测试过
  • @Anatoliy Nikolaev:已解决,但我不知道原因!

标签: wpf wpf-controls wpfdatagrid


【解决方案1】:

最终测试了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>

【讨论】:

    猜你喜欢
    • 2011-05-22
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2015-05-07
    • 2013-04-15
    • 1970-01-01
    相关资源
    最近更新 更多