ModelItem Class (System.Activities.Presentation.Model)

Switch View :
ScriptFree
.NET Framework Class Library
ModelItem Class

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

Inheritance Hierarchy

System.Object
  System.Activities.Presentation.Model.ModelItem
    System.Activities.Presentation.Model.ModelItemCollection
    System.Activities.Presentation.Model.ModelItemDictionary

Namespace:  System.Activities.Presentation.Model
Assembly:  System.Activities.Presentation (in System.Activities.Presentation.dll)
Syntax

Visual Basic
Public MustInherit Class ModelItem _
	Implements INotifyPropertyChanged
C#
public abstract class ModelItem : INotifyPropertyChanged
Visual C++
public ref class ModelItem abstract : INotifyPropertyChanged
F#
[<AbstractClass>]
type ModelItem =  
    class
        interface INotifyPropertyChanged
    end

The ModelItem type exposes the following members.

Constructors

  Name Description
Protected method ModelItem Creates a new ModelItem.
Top
Properties

  Name Description
Public property Attributes Returns the attributes declared on this item.
Public property Content Returns the ContentPropertyAttribute of the item, or null.
Public property ItemType Returns the type of object that the item represents.
Public property Name Represents the name or ID of the item.
Public property Parent Returns the item that is the parent of this item.
Public property Parents Returns all parents of this item.
Public property Properties Returns the public properties on this item.
Public property Root Returns the item that is the root of this tree.
Public property Source Returns the property that provided this value.
Public property Sources Returns all the properties that hold this value.
Public property View Returns a DependencyObject that graphically represents this item.
Top
Methods

  Name Description
Public method 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.
Public method 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.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCurrentValue Returns the current value of the underlying model object that the ModelItem is wrapping.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string representation of the underlying model object contained in this model item. (Overrides Object.ToString().)
Top
Events

  Name Description
Public event PropertyChanged Implements INotifyPropertyChanged. Use this event to listen for changes to the model. This is also used by the data binding features of WPF.
Top
Extension Methods

  Name Description
Public Extension Method Focus() Overloaded. Sets the keyboard focus on the specified designer item. (Defined by ModelItemExtensions.)
Public Extension Method Focus(Int32) Overloaded. Sets the keyboard focus on the specified designer item. (Defined by ModelItemExtensions.)
Public Extension Method GetEditingContext Retrieves the editing context of the specified model item. (Defined by ModelItemExtensions.)
Public Extension Method GetModelPath Retrieves the path of the specified model item. (Defined by ModelItemExtensions.)
Public Extension Method IsParentOf Returns a value that indicates whether the first specified designer item is a parent of the second specified designer item. (Defined by ModelItemExtensions.)
Top
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 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.

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 = { 
         {"noise", "snort" },
         {"MeanTimeUntilNaps", TimeSpan.FromMinutes(15) }
      },
      CloseRelatives = { 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");


Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference