ModelItem ModelItem ModelItem ModelItem Class

Definition

Represents a single item in the editing model. An item can be anything from a complex data structure down to a color or integer.

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
Inheritance
ModelItemModelItemModelItemModelItem
Derived
Implements

Examples

The ModelItem can be thought of as a thin proxy for an object at which it points. First define a simple Animal object.


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

Secondly, create an instance of that Animal and a ModelItem that is a proxy for it. The object can then be retrieved by calling GetCurrentValue. The following code also shows how to use other properties defined by 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");  

Remarks

You can access the item’s properties through its Properties collection and make changes to the values of the properties.

A ModelItem is a wrapper around the underlying data model of the designer. You can access the underlying model through the GetCurrentValue method.

Note

Any changes you make to an object returned from the GetCurrentValue method will not be reflected by the serialization and undo systems of the designer.

Constructors

ModelItem() ModelItem() ModelItem() ModelItem()

Creates a new instance of the ModelItem class.

Properties

Attributes Attributes Attributes Attributes

Gets the attributes declared on this item.

Content Content Content Content

Gets the ContentPropertyAttribute of the item, or null.

ItemType ItemType ItemType ItemType

Gets the type of object that the item represents.

Name Name Name Name

Gets or sets the name or ID of the item.

Parent Parent Parent Parent

Gets the item that is the parent of this item.

Parents Parents Parents Parents

Gets all parents of this item.

Properties Properties Properties Properties

Gets the public properties on this item.

Root Root Root Root

Gets the item that is the root of this tree.

Source Source Source Source

Gets the property that provided this value.

Sources Sources Sources Sources

Gets all the properties that hold this value.

View View View View

Gets a DependencyObject that graphically represents this item.

Methods

BeginEdit() BeginEdit() BeginEdit() BeginEdit()

Opens an editing scope for the designer. After an editing scope is open, all changes across all objects will be saved into the scope until the transaction is completed or reverted. Editing scopes can be nested, but must be committed in order.

BeginEdit(Boolean) BeginEdit(Boolean) BeginEdit(Boolean) BeginEdit(Boolean)

Opens an editing scope for the designer.

BeginEdit(String) BeginEdit(String) BeginEdit(String) BeginEdit(String)

Opens an editing scope for the designer. After an editing scope is open, all changes across all objects will be saved into the scope until the transaction is completed or reverted. Editing scopes can be nested, but must be committed in order.

BeginEdit(String, Boolean) BeginEdit(String, Boolean) BeginEdit(String, Boolean) BeginEdit(String, Boolean)

Opens an editing scope for the designer.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCurrentValue() GetCurrentValue() GetCurrentValue() GetCurrentValue()

Returns the current value of the underlying model object that the ModelItem is wrapping.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string representation of the underlying model object contained in this model item.

Events

PropertyChanged PropertyChanged PropertyChanged PropertyChanged

Implements INotifyPropertyChanged. Use this event to listen for changes to the model. This is also used by the data binding features of WPF.

Extension Methods

Focus(ModelItem) Focus(ModelItem) Focus(ModelItem) Focus(ModelItem)

Sets the keyboard focus on the specified designer item.

Focus(ModelItem, Int32) Focus(ModelItem, Int32) Focus(ModelItem, Int32) Focus(ModelItem, Int32)

Sets the keyboard focus on the specified designer item.

GetEditingContext(ModelItem) GetEditingContext(ModelItem) GetEditingContext(ModelItem) GetEditingContext(ModelItem)

Retrieves the editing context of the specified model item.

GetModelPath(ModelItem) GetModelPath(ModelItem) GetModelPath(ModelItem) GetModelPath(ModelItem)

Retrieves the path of the specified model item.

IsParentOf(ModelItem, ModelItem) IsParentOf(ModelItem, ModelItem) IsParentOf(ModelItem, ModelItem) IsParentOf(ModelItem, ModelItem)

Returns a value that indicates whether the first specified designer item is a parent of the second specified designer item.

Applies to