C# 属性和对象C

C# 属性和对象C,c#,wpf,object,properties,datagrid,C#,Wpf,Object,Properties,Datagrid,我想将获取和设置我从datagrid获取的对象的公共属性设置为。 我有一个datagrid,它有3列文本和3列复选框。 当我选中其中一个复选框时,我得到列表中整行的值,如下所示: var selectedItemsController = MyObsCollection.Where(n => n.Controller).ToList(); ObservableCollection<RowData> _obsCollection =

我想将获取和设置我从datagrid获取的对象的公共属性设置为。 我有一个datagrid,它有3列文本和3列复选框。 当我选中其中一个复选框时,我得到列表中整行的值,如下所示:

var selectedItemsController = MyObsCollection.Where(n => n.Controller).ToList();
ObservableCollection<RowData> _obsCollection =
                                new ObservableCollection<RowData>();
public ObservableCollection<RowData> MyObsCollection
{
   get { return _obsCollection; }
}
public class RowData : INotifyPropertyChanged
{
    public string Type { get; set; }
    public string MapTo { get; set; }
    public string Name { get; set; }
    public bool Controller { get; set; }
    public bool Service { get; set; }
    public bool Injection { get; set; }

    public RowData(string type, string mapTo, string name) 
    {
        Type = type;
        MapTo = mapTo;
        Name = name;
    }
public string AreaName
        {
            get { return AreaNameValue.Text; }
            set { AreaNameValue.Text = value; }
        }
这是一个对象列表,其中包含所有3个字符串值和所有3个bool值的复选框,它们位于名为Controller的列中的复选框所在的同一行中

MyobCollection也是ObservableCollection的公共属性,其定义如下:

var selectedItemsController = MyObsCollection.Where(n => n.Controller).ToList();
ObservableCollection<RowData> _obsCollection =
                                new ObservableCollection<RowData>();
public ObservableCollection<RowData> MyObsCollection
{
   get { return _obsCollection; }
}
public class RowData : INotifyPropertyChanged
{
    public string Type { get; set; }
    public string MapTo { get; set; }
    public string Name { get; set; }
    public bool Controller { get; set; }
    public bool Service { get; set; }
    public bool Injection { get; set; }

    public RowData(string type, string mapTo, string name) 
    {
        Type = type;
        MapTo = mapTo;
        Name = name;
    }
public string AreaName
        {
            get { return AreaNameValue.Text; }
            set { AreaNameValue.Text = value; }
        }
我要做的是在selectedItemsController中为该对象列表创建一个公共属性,以便在其他类中使用它

例如,我在做这件事时,使用了一个区域的名称,该区域也是WindowsForm的一部分。我从某个文本框中取了这个名字,并公开了如下内容:

var selectedItemsController = MyObsCollection.Where(n => n.Controller).ToList();
ObservableCollection<RowData> _obsCollection =
                                new ObservableCollection<RowData>();
public ObservableCollection<RowData> MyObsCollection
{
   get { return _obsCollection; }
}
public class RowData : INotifyPropertyChanged
{
    public string Type { get; set; }
    public string MapTo { get; set; }
    public string Name { get; set; }
    public bool Controller { get; set; }
    public bool Service { get; set; }
    public bool Injection { get; set; }

    public RowData(string type, string mapTo, string name) 
    {
        Type = type;
        MapTo = mapTo;
        Name = name;
    }
public string AreaName
        {
            get { return AreaNameValue.Text; }
            set { AreaNameValue.Text = value; }
        }
在那之后,我可以在另一节课上做到这一点:

var areaName = areaDialog.AreaName.Trim();

最后,我的问题是,如果DataGrid的名称是例如:tabela,那么有人知道如何为DataRow对象创建相同的公共属性吗?DataGrid中是否已经定义了我可以使用的东西?like'Text'属性用于InputExtBox。

您可以将selectedItemsController设置为DataGrid的datacontext。然后可以在selectedItemsController本身上设置和获取值