很抱歉,但我只找到了在列标记或旧样式
中定义FieldName的方法<xcdg:DataGridCollectionViewSource x:Key="cvsMetals" Source="{Binding MetalTypes}">
<xcdg:DataGridCollectionViewSource.GroupDescriptions>
<!--<PropertyGroupDescription PropertyName="Year" />-->
</xcdg:DataGridCollectionViewSource.GroupDescriptions>
</xcdg:DataGridCollectionViewSource>
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvsMetals} }" AutoCreateColumns="True">
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="Name" IsMainColumn="True"></xcdg:Column>
<xcdg:Column FieldName="Year"></xcdg:Column>
<xcdg:Column FieldName="SelectedMetalSeries.Name"></xcdg:Column>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>
SelectedMetalSeries.Name 的最后一列是具有属性的类。我没有找到一种方法来显示对象的属性名称
我的ViewModels:
public class AllMetalTypeViewModel : WorkspaceViewModel
{
private ObservableCollection<MetalTypeViewModel> _metalTypes;
public ObservableCollection<MetalTypeViewModel> MetalTypes
{
get { return _metalTypes; }
set { Set("MetalTypes", ref _metalTypes, value); }
}
public class MetalTypeViewModel: WorkspaceViewModel
{
private MetalSeries _selectedMetalSeries;
public MetalSeries SelectedMetalSeries
{
get { return _selectedMetalSeries; }
set { Set("SelectedMetalSeries", ref _selectedMetalSeries, value); }
}
private short _year;
public short Year
{
get { return _year; }
set { Set("Year", ref _year, value); }
}
private string _name;
public string Name
{
get { return _name; }
set { Set("Name", ref _name, value); }
}
public partial class MetalSeries
{
#region Primitive Properties
public virtual long ID
{
get;
set;
}
public virtual string Name
{
get;
set;
}
我发现旧样式似乎不再适用于新版本:
<ExtendedColumn:ExtendedDataGridTextColumn Header="Publisher" Binding="{Binding Publisher}" AllowAutoFilter="False" CanUserSort="False" Width="*"/>
问题是我找不到可以绑定ViewModel属性的属性
答案 0 :(得分:1)
这是一个FieldName而不是Binding,因为我认为它不支持嵌套。然而,“好”的设计不应该有这样的问题。我会尝试简单地为DataGrid创建一个专用的ViewModel。