无法在XamDataGrid中为XamComboEditor设置ItemsSource

时间:2014-07-17 09:52:19

标签: c# infragistics xamdatagrid

我需要显示来自一个类的XamDataGrid数据,该类包含一些属性和一个有效选项列表。类似的东西:

public class DataViewModel
{
    public string Identifier {get;private set;}
    public string Value {get;set;}
    public IEnumeranble<string> ValidValues {get; set;}
}

我正在尝试将设置设置为XamDataGrid,以便通过Identifier编辑一个不可编辑的Value列和XamComboEditor列。这是我提出的xaml:

    <igDP:XamDataGrid GroupByAreaLocation="None">
        <igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:FieldLayoutSettings AutoGenerateFields="False"/>
        </igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:XamDataGrid.FieldLayouts>
            <igDP:FieldLayout>
                <igDP:FieldLayout.Fields>
                    <igDP:Field Name="Identifier"/>
                    <igDP:Field Name="Value">
                        <igDP:Field.Settings>
                            <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
                                <igDP:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <Setter Property="IsEditable" Value="False" />
                                        <Setter Property="ItemsSource" Value="{Binding Path=DataContext.DataItem.Values, 
                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igEditors:XamComboEditor}}}" />
                                    </Style>
                                </igDP:FieldSettings.EditorStyle>
                            </igDP:FieldSettings>
                        </igDP:Field.Settings>
                    </igDP:Field>
                </igDP:FieldLayout.Fields>
            </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>

XamDataGrid上的数据绑定工作正常,但XamComboEditor.ItemsSource上的数据绑定不起作用,但我不确定如何修复ID。你有什么想法吗?

1 个答案:

答案 0 :(得分:2)

我找到了另一种使用事件的方法。

在XAML中,我必须指定那些设置而不是我的设置:

                            <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
                                <igDP:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <Style.Setters>
                                            <EventSetter Event="Loaded" Handler="XCEloaded"/>
                                            <Setter Property="IsEditable" Value="False" />
                                        </Style.Setters>
                                    </Style>
                                </igDP:FieldSettings.EditorStyle>
                            </igDP:FieldSettings>

我用这段代码处理了这个事件:

    private void XCEloaded(object sender, RoutedEventArgs e)
    {
        var drp = Utilities.GetAncestorFromType(sender as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
        if (drp.DataRecord.DataItem != null)
            (sender as XamComboEditor).ItemsSource = (drp.DataRecord.DataItem as DataViewModel).ValidValues;
    }

它看起来不是最干净的解决方案,但至少它可行。