具有绑定的扩展 WPF 工具包数据网格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15517095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:11:25  来源:igfitidea点击:

Extended WPF Toolkit Datagrid with binding

c#wpfmvvmdatagridwpftoolkit

提问by masterchris_99

Sorry but I only found the way with the FieldName defined in the column tag or the old style

抱歉,我只找到了在列标签中定义的 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>

The last column with SelectedMetalSeries.Nameis a class with properties. I didn't find a way to show this property name of the object

SelectedMetalSeries.Name的最后一列是一个具有属性的类。我没有找到显示对象的此属性名称的方法

My 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;
    }

I found the old style which seems no longer to work with the new version:

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

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

The problem is that I can't find a property where I can bind my ViewModel properties

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

DataGrid Version 1.9.0

数据网格 1.9.0 版

回答by Pellared

It is a FieldName not Binding and as I see it does not support nesting. However a "good" design should not have such issues. I would try simply creating a dedicated ViewModel for the DataGrid.

它是一个没有绑定的 FieldName,正如我所见,它不支持嵌套。然而,一个“好的”设计不应该有这样的问题。我会尝试简单地为 DataGrid 创建一个专用的 ViewModel。