【问题标题】:Items collection must be empty before using ItemsSource, wpf datagrid在使用 ItemsSource、wpf datagrid 之前,项目集合必须为空
【发布时间】:2014-01-07 19:38:03
【问题描述】:

我正在尝试将样式添加到数据网格,但出现此错误:

如果我评论样式部分一切正常。 这是我的 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>

【问题讨论】:

    标签: wpf datagrid itemscollection


    【解决方案1】:

    您已将 Style 添加为数据项,但显然想将其添加到 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>
    

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 1970-01-01
      • 2012-07-24
      • 2010-10-15
      • 1970-01-01
      • 2012-03-04
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多