2013-03-20 97 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。