C# 如何从DataGrid获取实体名称和类型?

C# 如何从DataGrid获取实体名称和类型?,c#,wpf,entity-framework,mvvm,C#,Wpf,Entity Framework,Mvvm,这似乎应该是直截了当的,但我似乎无法获得模型实体类型和名称 我可以获取类名称/类型,但不能获取编辑数据网格时访问的类中的属性 这是我试图获取值的事件: protected void OnDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) {

这似乎应该是直截了当的,但我似乎无法获得模型
实体
类型和名称

我可以获取
名称/类型,但不能获取编辑
数据网格时访问的
中的属性

这是我试图获取值的事件:

protected void OnDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        if (e.EditAction == DataGridEditAction.Commit)
        {
            var userControl = FindVisualParent<UserView>(sender as UIElement);
            var rowType = e.Row.Item.GetType(); //This gets the class type
               //trying to get name and type of entity here
            var name  = e.Row.Item. ??????
            var type = e.Row.Item.GetType(). ??????
        }            
    }

为了让事情更清楚一点,我正在尝试获取上述类中
属性
的名称和类型
命名
部分
。如何从
OnDataGrid\u CellEditEnding
事件中执行此操作?

将其转换为您的银行类<代码>银行iAmOfTypeBank=(银行)e.Row.Item
当您使用MVVM时,为什么您是一个
CellEditEndingEvent
而不是在viewmodel中这样做?另一个问题:为什么要将模型而不是viewmodel绑定到您的视图?@MightyBadaboom,它绑定到具有相同属性的包装类,我认为发布所有内容都会让事情变得混乱,但这些是我试图获取的属性名称和类型。还有你的另一个问题,我在视图模型中使用了一个属性更改事件,但在向datagrid添加新行时,空行不是绑定集合的一部分,因此我需要另一种方法才能向集合添加新数据。@KyloRen Ok。主要的问题是在你的收藏中添加一个新的条目?@MightyBadaboom,是的,这是一开始的主要问题。但是,我确实做到了,我只是想在网格中编辑某个属性时定义一些逻辑。我所做的是创建一个通用的Datagrid事件,我可以将它用于应用程序中的任何Datagrid。
public partial class Bank
{
    public System.Guid Id { get; set; } // ID (Primary key)
    public string Section { get; set; } // Section (length: 50)
    public string Name { get; set; } // Name (length: 50)

    public Bank()
    {
        InitializePartial();
    }

    partial void InitializePartial();
}