2013-03-20 100 views
2

很抱歉,但我只发现或列标签定义的字段名的老式扩展WPF工具包Datagrid的与结合

<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属性

DataGrid Version 1.9.0

+0

嗯...不知道数据源...你DataGridControl的ItemsSource是什么?底层虚拟机是什么样的? – DHN 2013-03-20 08:09:08

+0

我已经添加了类 – 2013-03-20 08:28:31

回答

1

这是一个字段名不具有约束力,因为我看到它不支持嵌套的属性。然而,一个“好”的设计不应该有这样的问题。我会尝试简单地为DataGrid创建一个专用的ViewModel。