Windows Server 2003/2008上的WPF:DataGridTemplateColumn

莫森

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

DataGridComboBoxColumn

我删除风格细胞和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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Windows Server上的AnyDesk

来自分类Dev

Windows Server 2008 R2上的WPF样式

来自分类Dev

WPF 应用程序在 Windows Server 2008 上崩溃

来自分类Dev

在Windows Server 2012上安装Windows Defender

来自分类Dev

Windows Server上的Laravel SSH

来自分类Dev

在Windows Server上安装Redis

来自分类Dev

在Windows Server上安装pdfgrep

来自分类Dev

Windows 8.1上的SQL Server 2012安装

来自分类Dev

Windows Server 2012(Azure)上的Umbraco 7.1.9

来自分类Dev

Windows Server上的Laravel Task Scheduler

来自分类Dev

Windows Server上的目录/文件监视

来自分类Dev

Maven组件无法在Windows Server上运行

来自分类Dev

在Windows 2016 Server上卸载服务

来自分类Dev

在Google Cloud Windows Server上使用python

来自分类Dev

Windows上的Azure Site Recovery + MySQL Server

来自分类Dev

在Node JS上生成(Windows Server 2012)

来自分类Dev

在Windows 10上安装Ubuntu Server 18.04.1?

来自分类Dev

Windows 7上的Apache Server开放端口?

来自分类Dev

在Windows Server上远程运行脚本

来自分类Dev

Windows Server上的永远离子视频

来自分类Dev

Maven组件无法在Windows Server上运行

来自分类Dev

Windows Server上的Apple Push Notifications证书

来自分类Dev

Windows Server上的Laravel Task Scheduler

来自分类Dev

在Windows XP上设置WAMP Server

来自分类Dev

在 Windows Server 2012 上安装 pip lxml

来自分类Dev

Azure 上的出厂重置 Windows Server 2016

来自分类Dev

无法在Windows Server 2012上安装SQL Server 2012

来自分类Dev

是否可以在Windows Server 2012上安装Windows Phone SDK

来自分类Dev

无法从Windows访问VMware上安装的Windows Server 2019