2013-12-19 89 views
0

我想樣式添加到DataGrid前空的,但我得到這個錯誤:如果我的評論風格的一部分,一切工作正常項目集合必須在使用ItemsSource,WPF數據網格

。 這是我的XAML,任何人都可以幫助我嗎?謝謝 安德烈

    <dg:SelfBindingDataGrid Grid.Row="1" ItemsSource="{Binding Path=CurrentMachine.LNE_AUTOMATION_PARAM, Mode=TwoWay}" 
           SelectedItem="{Binding Path=CurrentAutParameter}" IsReadOnly="False"> 
        <dg:SelfBindingDataGrid.Columns> 
         <dg:ExtDataGridComboBoxColumn Header="Spec. Element" Tag="CD_ELEMENT" Width="*" 
                  TextSearch.TextPath="description" 
                  SelectedValueBinding="{Binding Path=CD_ELEMENT, Mode=TwoWay, 
                   UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" 
                  ItemsSource="{Binding Source={StaticResource ElementView}}" 
                  SelectedValuePath="CD_ELEMENT" 
                  DisplayMemberPath="description"/> 
         <dg:ExtDataGridTextColumn Header="Case File" Width="*" Tag="ID_CASE_TEST_FILE_TO_UPPER"> 
         </dg:ExtDataGridTextColumn> 
         <dg:ExtDataGridNumericColumn Header="Case Index" Width="*" Tag="ID_INDEX"/> 
         <dg:ExtDataGridNumericColumn Header="MIN" Width="*" Tag="ID_RANGE_MIN"/> 
         <dg:ExtDataGridNumericColumn Header="MAX" Width="*" Tag="ID_RANGE_MAX"/> 
         <dg:ExtDataGridComboBoxColumn Header="Compile Method" Width="*" 
               ItemsSource="{Binding Source={x:Static local:AddMachineViewModel.ApproachList}, Mode=OneWay}" 
               SelectedValueBinding="{Binding Path=ID_COMMAND_FILE, Mode=TwoWay, 
                 UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" 
               SelectedValuePath="ID_TYPE" 
               DisplayMemberPath="FL_TYPE"/> 
        </dg:SelfBindingDataGrid.Columns> 
        <Style TargetType="DataGridRow"> 
         <Style.Resources> 
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue"/> 
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" /> 
          <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" /> 
          <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" /> 
         </Style.Resources> 
        </Style> 
       </dg:SelfBindingDataGrid> 
      </Grid> 
     </GroupBox> 

回答

2

您已經添加了樣式作爲數據項,但顯然希望將其添加到SelfBindingDataGrid的資源:

<dg:SelfBindingDataGrid ...> 
    <dg:SelfBindingDataGrid.Resources> 
     <Style TargetType="DataGridRow"> 
      ... 
     </Style> 
    </dg:SelfBindingDataGrid.Resources> 
    ... 
</dg:SelfBindingDataGrid> 

如果您打算設置SelfBindingDataGrid的風格,它應該看起來像這樣:

<dg:SelfBindingDataGrid ...> 
    <dg:SelfBindingDataGrid.Style> 
     <Style TargetType="dg:SelfBindingDataGrid"> 
      ... 
     </Style> 
    </dg:SelfBindingDataGrid.Style> 
    ... 
</dg:SelfBindingDataGrid> 
相關問題