ModelItem クラス

定義

編集モデル内の 1 つの項目を表します。 項目には、複雑なデータ構造から色や整数まで、あらゆるものがあります。

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 メソッドを使用してアクセスできます。

Note

GetCurrentValue メソッドから返されたオブジェクトに対して行った変更は、デザイナーのシリアル化および元に戻すシステムには反映されません。

コンストラクター

名前 説明
ModelItem()

ModelItem クラスの新しいインスタンスを作成します。

プロパティ

名前 説明
Attributes

この項目で宣言されている属性を取得します。

Content

項目またはContentPropertyAttributenullを取得します。

ItemType

項目が表すオブジェクトの型を取得します。

Name

アイテムの名前または ID を取得または設定します。

Parent

この項目の親である項目を取得します。

Parents

この項目のすべての親を取得します。

Properties

この項目のパブリック プロパティを取得します。

Root

このツリーのルートである項目を取得します。

Source

この値を指定したプロパティを取得します。

Sources

この値を保持するすべてのプロパティを取得します。

View

この項目をグラフィカルに表す DependencyObject を取得します。

メソッド

名前 説明
BeginEdit()

デザイナーの編集スコープを開きます。 編集スコープを開くと、トランザクションが完了または元に戻されるまで、すべてのオブジェクトのすべての変更がスコープに保存されます。 編集スコープは入れ子にできますが、順番にコミットする必要があります。

BeginEdit(Boolean)

デザイナーの編集スコープを開きます。

BeginEdit(String, Boolean)

デザイナーの編集スコープを開きます。

BeginEdit(String)

デザイナーの編集スコープを開きます。 編集スコープを開くと、トランザクションが完了または元に戻されるまで、すべてのオブジェクトのすべての変更がスコープに保存されます。 編集スコープは入れ子にできますが、順番にコミットする必要があります。

Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetCurrentValue()

ModelItemがラップしている基になるモデル オブジェクトの現在の値を返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

このモデル アイテムに含まれる基になるモデル オブジェクトの文字列形式を返します。

イベント

名前 説明
PropertyChanged

INotifyPropertyChangedを実装します。 このイベントを使用して、モデルの変更をリッスンします。 これは、WPF のデータ バインディング機能でも使用されます。

拡張メソッド

名前 説明
Focus(ModelItem, Int32)

指定したデザイナー項目にキーボード フォーカスを設定します。

Focus(ModelItem)

指定したデザイナー項目にキーボード フォーカスを設定します。

GetEditingContext(ModelItem)

指定したモデル 項目の編集コンテキストを取得します。

GetModelPath(ModelItem)

指定したモデル 項目のパスを取得します。

IsParentOf(ModelItem, ModelItem)

最初に指定したデザイナー項目が、2 番目に指定されたデザイナー項目の親であるかどうかを示す値を返します。

適用対象