DependencyObject.SetValue Metodo
Definizione
Imposta il valore locale di una proprietà di dipendenza.Sets the local value of a dependency property.
Overload
SetValue(DependencyProperty, Object) |
Imposta il valore locale di una proprietà di dipendenza, specificato dal relativo identificatore della proprietà di dipendenza.Sets the local value of a dependency property, specified by its dependency property identifier. |
SetValue(DependencyPropertyKey, Object) |
Imposta il valore locale di una proprietà di dipendenza di sola lettura, specificato dall'identificatore DependencyPropertyKey della proprietà di dipendenza.Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. |
SetValue(DependencyProperty, Object)
Imposta il valore locale di una proprietà di dipendenza, specificato dal relativo identificatore della proprietà di dipendenza.Sets the local value of a dependency property, specified by its dependency property identifier.
public:
void SetValue(System::Windows::DependencyProperty ^ dp, System::Object ^ value);
public void SetValue (System.Windows.DependencyProperty dp, object value);
member this.SetValue : System.Windows.DependencyProperty * obj -> unit
Public Sub SetValue (dp As DependencyProperty, value As Object)
Parametri
Identificatore della proprietà di dipendenza da impostare.The identifier of the dependency property to set.
- value
- Object
Nuovo valore locale.The new local value.
Eccezioni
Si è tentato di modificare una proprietà di dipendenza di sola lettura o una proprietà in un oggetto DependencyObject sealed.Attempted to modify a read-only dependency property, or a property on a sealed DependencyObject.
value
non è il tipo corretto registrato per la proprietà dp
.value
was not the correct type as registered for the dp
property.
Commenti
Se il tipo specificato non corrisponde al tipo dichiarato per la proprietà di dipendenza mentre è stata originariamente registrata, viene generata un'eccezione.If the provided type does not match the type that is declared for the dependency property as it was originally registered, an exception is thrown. Il value
parametro deve essere sempre fornito come tipo appropriato.The value
parameter should always be provided as the appropriate type.
Le condizioni di eccezione sono potenzialmente influenzate dal ValidateValueCallback callback esistente nell'identificatore della proprietà di dipendenza da impostare.The exception conditions are potentially influenced by the ValidateValueCallback callback that exists on the dependency property identifier of the dependency property being set. In caso contrario, il valore specificato potrebbe non riuscire a condizioni generali di controllo del tipo (ad esempio, passando una stringa quando il tipo nativo è Double).Otherwise, the value provided might be failing general type-checking conditions (for example, passing a string when the native type is Double).
Si applica a
SetValue(DependencyPropertyKey, Object)
Imposta il valore locale di una proprietà di dipendenza di sola lettura, specificato dall'identificatore DependencyPropertyKey della proprietà di dipendenza.Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.
public:
void SetValue(System::Windows::DependencyPropertyKey ^ key, System::Object ^ value);
public void SetValue (System.Windows.DependencyPropertyKey key, object value);
member this.SetValue : System.Windows.DependencyPropertyKey * obj -> unit
Public Sub SetValue (key As DependencyPropertyKey, value As Object)
Parametri
Identificatore DependencyPropertyKey della proprietà da impostare.The DependencyPropertyKey identifier of the property to set.
- value
- Object
Nuovo valore locale.The new local value.
Esempio
Nell'esempio seguente viene definita una proprietà di dipendenza di sola lettura, insieme a un oggetto public static readonly
DependencyProperty che fornisce l'esposizione di sola lettura necessaria per i consumer di proprietà e la funzione di accesso get per il CLRCLR wrapper.The following example defines a read-only dependency property, along with a public static readonly
DependencyProperty that provides necessary read-only exposure to property consumers, and the get accessor for the CLRCLR wrapper.
internal static readonly DependencyPropertyKey AquariumSizeKey = DependencyProperty.RegisterReadOnly(
"AquariumSize",
typeof(double),
typeof(Aquarium),
new PropertyMetadata(double.NaN)
);
public static readonly DependencyProperty AquariumSizeProperty =
AquariumSizeKey.DependencyProperty;
public double AquariumSize
{
get { return (double)GetValue(AquariumSizeProperty); }
}
Friend Shared ReadOnly AquariumSizeKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("AquariumSize", GetType(Double), GetType(Aquarium), New PropertyMetadata(Double.NaN))
Public Shared ReadOnly AquariumSizeProperty As DependencyProperty = AquariumSizeKey.DependencyProperty
Public ReadOnly Property AquariumSize() As Double
Get
Return CDbl(GetValue(AquariumSizeProperty))
End Get
End Property
Commenti
Questa firma viene in genere utilizzata quando si impostano i valori per le proprietà di dipendenza di sola lettura definite dalle classi personalizzate.This signature is generally used when you set values for read-only dependency properties that are defined by your custom classes. Generalmente, SetValue viene chiamato solo dal tipo che ha registrato la proprietà di dipendenza, che implementa la logica interna che fornisce il valore determinato per la proprietà di dipendenza.Generally, SetValue is called only from the type that registered that dependency property, which implements the internal logic that provides the determined value for the dependency property. Per altre informazioni, vedere Proprietà di dipendenza di sola lettura.For more information, see Read-Only Dependency Properties.
Se il tipo specificato non corrisponde al tipo dichiarato per la proprietà di dipendenza mentre è stata originariamente registrata, viene generata un'eccezione.If the provided type does not match the type that is declared for the dependency property as it was originally registered, an exception is thrown. Il value
parametro deve essere sempre fornito come tipo appropriato.The value
parameter should always be provided as the appropriate type. Le condizioni di eccezione sono potenzialmente influenzate dal ValidateValueCallback callback esistente nell'identificatore della proprietà di dipendenza da impostare.The exception conditions are potentially influenced by the ValidateValueCallback callback that exists on the dependency property identifier of the dependency property being set.