ModelItem 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示编辑模型中的单个项。 项可以为从复杂的数据结构直至颜色或整数的任何内容。
public ref class ModelItem abstract : System::ComponentModel::INotifyPropertyChanged
	public abstract class ModelItem : System.ComponentModel.INotifyPropertyChanged
	type ModelItem = class
    interface INotifyPropertyChanged
	Public MustInherit Class ModelItem
Implements INotifyPropertyChanged
		- 继承
 - 
				ModelItem
 
- 派生
 
- 实现
 
示例
可以将 ModelItem 视为它所指处对象的瘦代理。 首先定义一个简单的 Animal 对象。
public class Animal  
{  
    // simple property  
    public string Name { get; set; }  
    // complex property   
    public Location Residence { get; set; }   
    // list   
    public List<Animal> CloseRelatives { get; set; }  
    // dictionary  
    public Dictionary<string, object> Features { get; set; }   
}  
public class Location  
{  
    public string StreetAddress { get; set; }  
    public string City { get; set; }  
    public string State { get; set; }   
}  
其次,创建该 Animal 的实例,以及作为其代理的 ModelItem。 然后,可以通过调用 GetCurrentValue 检索该对象。 下面的代码还演示如何使用 ModelItem 定义的其他属性。
EditingContext ec = new EditingContext();  
var companion1 = new Animal { Name = "Houdini the parakeet" };  
var companion2 = new Animal { Name = "Groucho the fish" };  
var animal = new Animal   
   {  
      Name = "Sasha the pug",  
      Residence = new Location   
      {  
         StreetAddress = "123 Main Street",  
         City = "AnyTown",  
         State = "Washington"  
      },  
      Features = new Dictionary<string, object> {   
         {"noise", "snort" },  
         {"MeanTimeUntilNaps", TimeSpan.FromMinutes(15) }  
      },  
      CloseRelatives = new List<Animal> { companion1, companion2 }   
   };  
ModelTreeManager mtm = new ModelTreeManager(ec);  mtm.Load(animal);  
ModelItem mi = mtm.Root;  
//Testing other properties of the class  
ModelItem root = mtm.Root;  
Assert.IsTrue(root.GetCurrentValue() == animal, "GetCurrentValue() returns same object");  
Assert.IsTrue(root.ItemType == typeof(Animal),"ItemType describes the item");  
Assert.IsTrue(root.Parent == null,"root parent is null");  
Assert.IsTrue(root.Source == null, "root source is null");  
Assert.IsTrue(((List<Animal>)root.Properties["CloseRelatives"].ComputedValue)[0] == companion1,   
   "ComputedValue of prop == actual object");  
Assert.IsFalse(((List<Animal>)root.Properties["CloseRelatives"].ComputedValue)[0] == companion2,   
   "ComputedValue of prop == actual object");  
Assert.AreEqual(root.Properties["Residence"].  
   Value.  
   Properties["StreetAddress"].  
   Value.GetCurrentValue(), "123 Main Street", "get actual value back out");  
Assert.AreEqual(root, root.Properties["Residence"].Parent, "property points to owner");  
ModelItem location = root.Properties["Residence"].Value;  
Assert.AreEqual(root.Properties["Residence"], location.Source, "sources point to the right place");  
	注解
可以通过项的集合访问项的属性 Properties ,并更改属性的值。
ModelItem 是设计器的基础数据模型周围的包装。 可以通过 GetCurrentValue 方法访问该基础模型。
注意
对 GetCurrentValue 方法返回的对象所做的任何更改将不受设计器的序列化和撤消系统的影响。
构造函数
| ModelItem() | 
		 创建 ModelItem 类的新实例。  | 
        	
属性
| Attributes | 
		 获取在此项上声明的特性。  | 
        	
| Content | 
		 获取项的   | 
        	
| ItemType | 
		 获取返回项所表示的对象的类型。  | 
        	
| Name | 
		 获取或设置项的名称或 ID 。  | 
        	
| Parent | 
		 获取返回作为此项的父级的项。  | 
        	
| Parents | 
		 获取此项的所有父级。  | 
        	
| Properties | 
		 设置此项上的公共属性。  | 
        	
| Root | 
		 获取返回作为此树的根的项。  | 
        	
| Source | 
		 获取提供此值的属性。  | 
        	
| Sources | 
		 获取保存此值的所有属性。  | 
        	
| View | 
		 获取以图形方式表示此项的 DependencyObject。  | 
        	
方法
| BeginEdit() | 
		 打开设计器的编辑范围。 打开编辑范围后,所有对象之间的所有更改将保存到该范围中,直至事务完成或还原为止。 编辑范围可以嵌套,但必须按顺序提交。  | 
        	
| BeginEdit(Boolean) | 
		 打开设计器的编辑范围。  | 
        	
| BeginEdit(String) | 
		 打开设计器的编辑范围。 打开编辑范围后,所有对象之间的所有更改将保存到该范围中,直至事务完成或还原为止。 编辑范围可以嵌套,但必须按顺序提交。  | 
        	
| BeginEdit(String, Boolean) | 
		 打开设计器的编辑范围。  | 
        	
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetCurrentValue() | 
		 返回 ModelItem 所包装的基础模型对象的当前值。  | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		 返回此模型项中包含的基础模型对象的字符串表示形式。  | 
        	
事件
| PropertyChanged | 
		 实现   | 
        	
扩展方法
| Focus(ModelItem) | 
		 将键盘焦点置于指定的设计器项上。  | 
        	
| Focus(ModelItem, Int32) | 
		 将键盘焦点置于指定的设计器项上。  | 
        	
| GetEditingContext(ModelItem) | 
		 检索指定模型项的编辑上下文。  | 
        	
| GetModelPath(ModelItem) | 
		 检索指定模型项的路径。  | 
        	
| IsParentOf(ModelItem, ModelItem) | 
		 返回一个值,该值指示第一个指定设计器项是否为第二个指定设计器项的父级。  |