ModelItem Classe
Definição
Representa um item único no modelo de edição.Represents a single item in the editing model. Um item pode ser qualquer coisa, desde uma estrutura de dados complexos até uma cor ou um inteiro.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
- Herança
-
ModelItem
- Derivado
- Implementações
Exemplos
O ModelItem pode ser considerado um proxy fino para um objeto no qual ele aponta.The ModelItem can be thought of as a thin proxy for an object at which it points. Primeiro, defina um Animal objeto simples.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; }
}
Em segundo lugar, crie uma instância desse Animal e uma ModelItem que seja um proxy para ele.Secondly, create an instance of that Animal and a ModelItem that is a proxy for it. O objeto pode então ser recuperado chamando GetCurrentValue .The object can then be retrieved by calling GetCurrentValue. O código a seguir também mostra como usar outras propriedades definidas pelo ModelItem .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");
Comentários
Você pode acessar as propriedades do item por meio de sua Properties coleção e fazer alterações nos valores das propriedades.You can access the item's properties through its Properties collection and make changes to the values of the properties.
Um ModelItem é um wrapper em volta do modelo de dados subjacente do designer.A ModelItem is a wrapper around the underlying data model of the designer. Você pode acessar o modelo subjacente por meio do GetCurrentValue método.You can access the underlying model through the GetCurrentValue method.
Observação
As alterações feitas em um objeto retornado do GetCurrentValue método não serão refletidas pelos sistemas de serialização e desfazer do designer.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.
Construtores
| ModelItem() |
Cria uma nova instância da classe ModelItem.Creates a new instance of the ModelItem class. |
Propriedades
| Attributes |
Obtém os atributos declarados neste item.Gets the attributes declared on this item. |
| Content |
Obtém o |
| ItemType |
Obtém o tipo de objeto que o item representa.Gets the type of object that the item represents. |
| Name |
Obtém ou define o nome ou a ID do item.Gets or sets the name or ID of the item. |
| Parent |
Obtém o item que é o pai deste item.Gets the item that is the parent of this item. |
| Parents |
Obtém todos os pais desse item.Gets all parents of this item. |
| Properties |
Obtém as propriedades públicas neste item.Gets the public properties on this item. |
| Root |
Obtém o item que é a raiz dessa árvore.Gets the item that is the root of this tree. |
| Source |
Obtém a propriedade que forneceu esse valor.Gets the property that provided this value. |
| Sources |
Obtém todas as propriedades que contêm esse valor.Gets all the properties that hold this value. |
| View |
Obtém um DependencyObject que representa graficamente esse item.Gets a DependencyObject that graphically represents this item. |
Métodos
| BeginEdit() |
Abre um escopo de edição para o designer.Opens an editing scope for the designer. Depois de abrir um escopo de edição, todas as alterações em todos os objetos serão salvas no escopo até que a transação seja concluída ou revertida.After an editing scope is open, all changes across all objects will be saved into the scope until the transaction is completed or reverted. Escopos de edição podem ser aninhados, mas devem ser confirmados na ordem.Editing scopes can be nested, but must be committed in order. |
| BeginEdit(Boolean) |
Abre um escopo de edição para o designer.Opens an editing scope for the designer. |
| BeginEdit(String) |
Abre um escopo de edição para o designer.Opens an editing scope for the designer. Depois de abrir um escopo de edição, todas as alterações em todos os objetos serão salvas no escopo até que a transação seja concluída ou revertida.After an editing scope is open, all changes across all objects will be saved into the scope until the transaction is completed or reverted. Escopos de edição podem ser aninhados, mas devem ser confirmados na ordem.Editing scopes can be nested, but must be committed in order. |
| BeginEdit(String, Boolean) |
Abre um escopo de edição para o designer.Opens an editing scope for the designer. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetCurrentValue() |
Retorna o valor atual do objeto de modelo subjacente que o ModelItem está encapsulando.Returns the current value of the underlying model object that the ModelItem is wrapping. |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma representação de cadeia de caracteres do objeto de modelo subjacente contido neste item de modelo.Returns a string representation of the underlying model object contained in this model item. |
Eventos
| PropertyChanged |
Implementa |
Métodos de Extensão
| Focus(ModelItem) |
Define o foco do teclado no item de designer especificado.Sets the keyboard focus on the specified designer item. |
| Focus(ModelItem, Int32) |
Define o foco do teclado no item de designer especificado.Sets the keyboard focus on the specified designer item. |
| GetEditingContext(ModelItem) |
Recupera o contexto de edição do item de modelo especificado.Retrieves the editing context of the specified model item. |
| GetModelPath(ModelItem) |
Recupera o caminho do item de modelo especificado.Retrieves the path of the specified model item. |
| IsParentOf(ModelItem, ModelItem) |
Retorna um valor que indica se o primeiro item de designer especificado é um pai do segundo item designer especificado.Returns a value that indicates whether the first specified designer item is a parent of the second specified designer item. |