XamDataGrid绑定问题

时间:2010-05-29 07:14:41

标签: c# wpf

我想通过集合的(CurrentEntity.INVTransactions)属性(BatchList)使用ComboBox控件绑定XamDataGrid的单元格,但它不起作用。 我正在使用mvvm模式。在我的代码中,“BatchId”和“BatchList”是CurrentEntity.INVTransactions集合的属性。

您能否告诉我为什么xamDataGrid的comboBox不显示BatchList?

示例代码:

<UserControl x:Class="PDCL.ERP.Modules.Inventory.Views.RequisitionList.RequisitionInfoUserControl"
            ...>    
        <GroupBox Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Header="Details" VerticalAlignment="Top" Margin="5,0,5,0">
        <Grid>
            <igDP:XamDataGrid Margin="2"  DataSource="{Binding CurrentEntity.INVTransactions}" x:Name="requisitionDeailsGrid" InitializeRecord="requisitionDeailsGrid_InitializeRecord">                   
                <igDP:XamDataGrid.FieldLayoutSettings>
                    <igDP:FieldLayoutSettings HighlightAlternateRecords="True" 
                                      AutoGenerateFields="False" 
                                      AllowAddNew="True" 
                                      AddNewRecordLocation="OnBottom" 
                                      AutoFitMode="Always"
                                      SupportDataErrorInfo="RecordsAndCells"
                                      DataErrorDisplayMode="ErrorIcon"
                                      />
                </igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:XamDataGrid.FieldLayouts>
                    <igDP:FieldLayout>
                        <igDP:FieldLayout.Fields>
                            <igDP:Field Name="Remarks" Label="Remarks" Width="Auto">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings AllowEdit="True" AllowResize="True"/>
                                </igDP:Field.Settings>
                            </igDP:Field>                               
                            <igDP:Field Name="BatchId" Label="Batch" Width="Auto">
                                <igDP:Field.Settings>                                        
                                    <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
                                        <igDP:FieldSettings.EditorStyle>
                                            <Style TargetType="{x:Type igEditors:XamComboEditor}">                                                    
                                                <Setter Property="ItemsSource" Value="{Binding INVTransactions.BatchList, RelativeSource = {RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}, AncestorLevel=1}}" />                                                    
                                                <Setter Property="DisplayMemberPath" Value="BatchName" />
                                                <Setter Property="ValuePath" Value="BatchId" />
                                            </Style>
                                        </igDP:FieldSettings.EditorStyle>

                                    </igDP:FieldSettings>
                                </igDP:Field.Settings>
                            </igDP:Field>
                            <igDP:Field Name="Qty" Label="Qty Supplied" Width="Auto">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings AllowEdit="True" AllowResize="True"/>
                                </igDP:Field.Settings>
                            </igDP:Field>
                        </igDP:FieldLayout.Fields>
                    </igDP:FieldLayout>
                </igDP:XamDataGrid.FieldLayouts>
            </igDP:XamDataGrid>
            </Grid>
    </GroupBox>
    </UserControl>

输出窗口显示错误“BindingExpression path error:'INVTransactions'属性未找到'object'''XamDataGrid'(Name ='requisitionDeailsGrid')'。BindingExpression:Path = INVTransactions.BatchList; DataItem ='XamDataGrid' (Name ='requisitionDeailsGrid'); target元素是'XamComboEditor'(Name =''); target属性是'ItemsSource'(类型'IEnumerable')“

1 个答案:

答案 0 :(得分:2)

您正在将Item绑定到Xamdatagrid的相对源,XamDataGrid没有INVTransactions属性,我认为您实际上正在寻找已绑定到INVTranactions属性的数据源,因此请尝试将绑定更改为。

{Binding DataSource.BatchList, RelativeSource = {RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}, AncestorLevel=1}}