无法在具有通过数据项集合显式添加的项的数据呈现器上设置数据源

cannot Set the datasource on a datapresenter that has items added explicitly through data items collection

我在 MainViewModel 中有一个集合,因为

     View = new List<Group>
            { 
                new Group
                {
                    Name = "Sagar Yadwad",GroupName = string.Empty,IsEnabled = true,LdapStatus="Pending"
                },
                new Group
                {
                    Name = "Sagar Yadwad1",GroupName = string.Empty,IsEnabled = false,LdapStatus="Pending"
                }

            };
        View1 = new ListCollectionView(View);

        View1.Filter = (e) =>
        {
            Group g = e as Group;
            return g.IsEnabled;
        };

现在,我将上面的 ViewModel 绑定到 XamDatagrid,代码如下:-

          <igDp:XamDataGrid x:Name="XamDataGridGroup"  DataSource="{Binding View1}" Width="950"   FontStyle="Normal" FontFamily="Siemens Sans" Background="#F2F2F2" RecordFilterDropDownPopulating="GroupDataGrid_OnRecordFilterDropDownPopulating"  GroupByAreaLocation="None" AllowDrop="True" IsSynchronizedWithCurrentItem="True" UpdateMode="OnUpdate" >
                <UserControl>

                </UserControl>
                <igDp:XamDataGrid.Resources>
                    <Style TargetType="{x:Type igDp:DataRecordPresenter}">
                        <Setter Property="IsSelected" Value="{Binding DataItem.IsSelected, Mode=TwoWay}"/>
                    </Style>
                    <Style TargetType="Button" x:Key="{ComponentResourceKey {x:Type igDp:XamDataGrid}, ButtonStyle}" BasedOn="{StaticResource  BaseButtonStyle}"/>
                    <Style TargetType="igWindows:PopupResizerBar" >
                        <Setter Property="Visibility" Value="Hidden"></Setter>
                    </Style>
                </igDp:XamDataGrid.Resources>
                <igDp:XamDataGrid.FieldLayoutSettings>
                    <igDp:FieldLayoutSettings AllowRecordFixing="No"  
                                      AllowDelete="False"
                                      HighlightAlternateRecords="False" 
                                      RecordSelectorLocation="None"
                                      SelectionTypeRecord="Single"  
                                      SelectionTypeCell="Single" FilterUIType="LabelIcons"
                                      AutoGenerateFields="False" AllowFieldMoving="No"
                                      RecordSelectorExtent="1"/>
                </igDp:XamDataGrid.FieldLayoutSettings>


                <igDp:XamDataGrid.FieldSettings >
                    <igDp:FieldSettings  
                LabelTextWrapping="NoWrap" 
                FilterLabelIconDropDownType="MultiSelectExcelStyle"  
                AllowRecordFiltering="True" AllowCellVirtualization="False" 
                AllowLabelVirtualization="False" Width="Auto" CellWidth="100"
                CellMinWidth="50"/>
                </igDp:XamDataGrid.FieldSettings>
                <igDp:XamDataGrid.FieldLayouts>
                    <igDp:FieldLayout>
                        <!--<igDp:FieldLayout.Fields>
                <igDp:Field Name="Name" AllowEdit="False" AllowRecordFiltering="True"></igDp:Field>
            </igDp:FieldLayout.Fields>-->
                        <igDp:UnboundField  Width="300"  Label="{LocText props:Resources.GROUPLIST_NAME}" BindingPath="Name" ToolTip="{LocText props:Resources.GROUPLIST_NAME}">

                            <igDp:UnboundField.Settings>
                                <igDp:FieldSettings>
                                    <igDp:FieldSettings.LabelPresenterStyle >
                                        <Style  TargetType="igDp:LabelPresenter"  BasedOn="{StaticResource GmsLabelStyle }">
                                            <Setter Property="AutomationProperties.AutomationId" Value="Groups_Column"></Setter>
                                        </Style>
                                    </igDp:FieldSettings.LabelPresenterStyle>
                                    <igDp:FieldSettings.CellValuePresenterStyle>
                                        <Style TargetType="{x:Type igDp:CellValuePresenter}">
                                            <Setter Property="Margin" Value="2"></Setter>

                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="igDp:CellValuePresenter">
                                                    <TextBlock TextAlignment="Left" Text="{Binding Path=DataContext.DataItem.Name,  RelativeSource={ RelativeSource Mode=TemplatedParent}}"
                                                           VerticalAlignment="Center"  />
                                                        <!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->

                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </igDp:FieldSettings.CellValuePresenterStyle>
                                </igDp:FieldSettings>
                            </igDp:UnboundField.Settings>

                        </igDp:UnboundField>
                        <igDp:UnboundField Width="350" Label="{LocText props:Resources.GROUPLIST_LDAP_USERS}" BindingPath="GroupName" ToolTip="{LocText props:Resources.GROUPLIST_LDAP_USERS}">

                            <igDp:UnboundField.Settings>
                                <igDp:FieldSettings>
                                    <igDp:FieldSettings.LabelPresenterStyle >
                                        <Style  TargetType="igDp:LabelPresenter"  BasedOn="{StaticResource GmsLabelStyle }">
                                            <Setter Property="AutomationProperties.AutomationId" Value="Group_Name"></Setter>
                                        </Style>
                                    </igDp:FieldSettings.LabelPresenterStyle>
                                    <igDp:FieldSettings.CellValuePresenterStyle>
                                        <Style TargetType="{x:Type igDp:CellValuePresenter}">
                                            <Setter Property="Margin" Value="2"></Setter>

                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="igDp:CellValuePresenter">
                                                        <TextBlock AllowDrop="True"  Text="{Binding Path=DataContext.DataItem.GroupName,  RelativeSource={ RelativeSource Mode=TemplatedParent}}"
                                                           VerticalAlignment="Center"  TextAlignment="Center" />
                                                        <!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->

                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </igDp:FieldSettings.CellValuePresenterStyle>
                                </igDp:FieldSettings>
                            </igDp:UnboundField.Settings>

                        </igDp:UnboundField>
                        <igDp:UnboundField Width="100" Label="{LocText props:Resources.GROUPLIST_SYNC}" BindingMode="TwoWay"  BindingPath="IsEnabled" Converter="{StaticResource BoolToUMDirectoryFilter}" ConverterParameter="Enabled"  ToolTip="{LocText props:Resources.GROUPLIST_SYNC}">
                            <igDp:UnboundField.Settings>
                                <igDp:FieldSettings AllowEdit="True">
                                    <igDp:FieldSettings.LabelPresenterStyle >
                                        <Style  TargetType="igDp:LabelPresenter"  BasedOn="{StaticResource GmsLabelStyle }">
                                            <Setter Property="AutomationProperties.AutomationId" Value="Group_SYNC"></Setter>
                                        </Style>
                                    </igDp:FieldSettings.LabelPresenterStyle>
                                    <igDp:FieldSettings.CellValuePresenterStyle>
                                        <Style TargetType="{x:Type igDp:CellValuePresenter}">
                                            <Setter Property="Margin" Value="2"></Setter>
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="igDp:CellValuePresenter">
                                                        <CheckBox IsChecked="{Binding Path=DataContext.DataItem.IsEnabled,  RelativeSource={ RelativeSource Mode=TemplatedParent}}"
                                                          HorizontalAlignment="Center" HorizontalContentAlignment="Center" Click="ButtonBase_OnClick">

                                                        </CheckBox>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </igDp:FieldSettings.CellValuePresenterStyle>
                                </igDp:FieldSettings>
                            </igDp:UnboundField.Settings>
                        </igDp:UnboundField>
                    <igDp:UnboundField Width="140" Label="{LocText props:Resources.GROUPLIST_LDAP_STATUS}" BindingPath="LdapStatus" ToolTip="{LocText props:Resources.GROUPLIST_LDAP_STATUS}">

                        <igDp:UnboundField.Settings>
                            <igDp:FieldSettings>
                                <igDp:FieldSettings.LabelPresenterStyle >
                                    <Style  TargetType="igDp:LabelPresenter"  BasedOn="{StaticResource GmsLabelStyle }">
                                        <Setter Property="AutomationProperties.AutomationId" Value="Group_Status"></Setter>
                                    </Style>
                                </igDp:FieldSettings.LabelPresenterStyle>
                                <igDp:FieldSettings.CellValuePresenterStyle>
                                    <Style TargetType="{x:Type igDp:CellValuePresenter}">
                                        <Setter Property="Margin" Value="2"></Setter>

                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="igDp:CellValuePresenter">
                                                    <TextBlock  Text="{Binding Path=DataContext.DataItem.LdapStatus,  RelativeSource={ RelativeSource Mode=TemplatedParent}}"
                                                           VerticalAlignment="Center" TextAlignment="Center"/>
                                                    <!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->

                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </igDp:FieldSettings.CellValuePresenterStyle>
                            </igDp:FieldSettings>
                        </igDp:UnboundField.Settings>

                    </igDp:UnboundField>
                </igDp:FieldLayout>
                </igDp:XamDataGrid.FieldLayouts>
            </igDp:XamDataGrid>

我收到一条错误消息,指出“无法在通过数据项集合显式添加项的数据展示器上设置数据源”。任何帮助将非常感激。 提前致谢, 萨加尔亚德瓦德

XamDataGrid 中删除 UserControl:

<igDp:XamDataGrid x:Name="XamDataGridGroup"  DataSource="{Binding View1}" ...>
    <UserControl>

    </UserControl>
...