Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带绑定的扩展WPF工具包Datagrid_C#_Wpf_Mvvm_Datagrid_Wpftoolkit - Fatal编程技术网

C# 带绑定的扩展WPF工具包Datagrid

C# 带绑定的扩展WPF工具包Datagrid,c#,wpf,mvvm,datagrid,wpftoolkit,C#,Wpf,Mvvm,Datagrid,Wpftoolkit,抱歉,我只找到了列标记中定义的字段名或旧样式的方法 <xcdg:DataGridCollectionViewSource x:Key="cvsMetals" Source="{Binding MetalTypes}"> <xcdg:DataGridCollectionViewSource.GroupDescriptions> <!--<PropertyGroupDescription PropertyName="Year" />-

抱歉,我只找到了列标记中定义的字段名或旧样式的方法

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

我发现旧样式似乎不再适用于新版本:

<ExtendedColumn:ExtendedDataGridTextColumn Header="Publisher" Binding="{Binding Publisher}" AllowAutoFilter="False" CanUserSort="False" Width="*"/>

问题是我找不到可以绑定ViewModel属性的属性


它是一个不绑定的字段名,我认为它不支持嵌套。然而,“好”的设计不应该有这样的问题。我会尝试为DataGrid创建一个专用的ViewModel。

Hmm…而不知道数据源…您的
DataGridControl的
ItemsSource
是什么?底层VM看起来像什么?我已经添加了类
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="*"/>