我认为这应该很容易,但我无法将 itemssource 值绑定到作为分层 XamDataGrid 一部分的组合框列上。我的 datacontext 在包含数据网格的 GRID 上设置为一个集合。
层次结构高层如下所示:
表(根)--> 字段(此处定义的组合框集合)--> 映射(此处的组合框列)
每个字段都可以有自己的映射,映射上的目标值对于每个字段都是唯一的。
在后面的代码中,我建立了我的集合并将 DataContext 设置为 Grid: DataGridTransformations.DataContext = MapColl;
这是一个可以帮助我理解的屏幕:
这是 XAML:
<Grid x:Name="GridTransformations" Background="#FFFAFADB" DataContext="MSC_Conversion_Tools.Models.MapSourceColl">
<Custom:XamDataGrid x:Name="DataGridTransformations" DataSource="{Binding TableEntities}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="600" Width="966" Loaded="DataGridTransformations_Loaded">
<Custom:XamDataGrid.FieldLayouts>
<Custom:FieldLayout>
<Custom:FieldLayout.Fields>
<Custom:Field Name="TableEntities"/>
</Custom:FieldLayout.Fields>
</Custom:FieldLayout>
<Custom:FieldLayout Key="TableEntities">
<Custom:FieldLayout.Fields>
<Custom:Field Name="EntityName" Label="Table Name"></Custom:Field>
<Custom:Field Name="Fields"/>
</Custom:FieldLayout.Fields>
</Custom:FieldLayout>
<Custom:FieldLayout Key="Fields">
<Custom:FieldLayout.Fields>
<Custom:Field Name="FieldName" Label="Field"></Custom:Field>
<Custom:Field Name="DefaultValue" Label="Default Value"></Custom:Field>
<Custom:Field Name="DefaultOnlyNonNullValues" Label="Default: Include Null Fields?" Width="300"></Custom:Field>
<Custom:Field Name="FunctionWrapName" Label="Function"></Custom:Field>
<Custom:Field Name="Mappings"></Custom:Field>
</Custom:FieldLayout.Fields>
</Custom:FieldLayout>
<Custom:FieldLayout Key="Mappings">
<Custom:FieldLayout.Fields>
<Custom:Field Name="SourceValue" Label="Source Vaue"></Custom:Field>
<Custom:Field Name="TargetValue" Label="Target Value" >
<Custom:Field.Settings>
<Custom:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True">
<Custom:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsSource" Value="{Binding Path=DataContext.MappingTargetCmbValues, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Custom:XamDataGrid}}}" />
<Setter Property="DisplayMemberPath" Value="Name"/>
<Setter Property="ValuePath" Value="Id" />
</Style>
</Custom:FieldSettings.EditorStyle>
</Custom:FieldSettings>
</Custom:Field.Settings>
</Custom:Field>
</Custom:FieldLayout.Fields>
</Custom:FieldLayout>
</Custom:XamDataGrid.FieldLayouts>
</Custom:XamDataGrid>
</Grid>
这也是我的 Field 类,其中包含我的组合框值集合 MappingTargetCmbValues(我可能也没有这样做):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace MSC_Conversion_Tools.Models
{
class Field
{
public Field(string Name)
{
FieldName = Name;
DefaultOnlyNonNullValues = false;
}
public string FieldName { get; set; }
public string DefaultValue { get; set; }
public Boolean DefaultOnlyNonNullValues { get; set; }
public string FunctionWrapName { get; set; }
public ObservableCollection<Mapping> Mappings { get; set; }
public ObservableCollection<MappingTargetCmbValue> MappingTargetCmbValues;
}
}
任何帮助将不胜感激。谢谢 !