我认为这应该很简单,但我在将comss列上的itemssource值绑定时遇到了问题,该列是分层XamDataGrid的一部分。我的datacontext在包含数据网格的GRID上设置为集合。
hiererchy高级看起来像这样:
表(根) - > Field(此处定义的Combobox集合) - >映射(此处为Combobox列)
每个字段都可以有自己的映射,映射上的目标值对每个字段都是唯一的。
在后面的代码中,我构建了我的集合并将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;
}
}
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
我可能会弄错,但看起来 MappingTargetCmbValues 是一个字段而不是属性。 Btw绑定到Host.DataContext.MappingTargetCmbValues与RelativeSource为SelfS可能会比FindAncestor绑定更好。