2013-08-31 89 views
1

上DataGridTemplateColumn我有一個DataGridTemplateColumnWPF:於Windows Server 2003/2008

<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罰款,但測試了他們的勝利Server 2008和2003上其結果:

DataGridComboBoxColumn

我重新感動風格細胞和DataGrid但仍 的(正如你看到的)ComboBox項目不會出現

+0

,什麼是問題? –

+0

@Anatoliy Nikolaev:剛剛添加 – Mohsen

+0

您是否在其他操作系統下測試過該程序? (Windows XP,Windows 8)。 –

回答

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> 
相關問題