DependencyPropertyChangedCallback Délégué
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Représente le rappel appelé lorsqu’une valeur de propriété change, pour les notifications de modification de propriété inscrites auprès de la technique RegisterPropertyChangedCallback .
public delegate void DependencyPropertyChangedCallback(DependencyObject ^ sender, DependencyProperty ^ dp);
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(1166556438, 10175, 19393, 172, 38, 148, 193, 96, 31, 58, 73)]
class DependencyPropertyChangedCallback : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(1166556438, 10175, 19393, 172, 38, 148, 193, 96, 31, 58, 73)]
public delegate void DependencyPropertyChangedCallback(DependencyObject sender, DependencyProperty dp);
Public Delegate Sub DependencyPropertyChangedCallback(sender As DependencyObject, dp As DependencyProperty)
- sender
- DependencyObject
L’objet instance qui contient la propriété pour s’inscrire pour la notification de modification de propriété.
Identificateur de propriété de dépendance de la propriété à inscrire pour la notification de modification de propriété.
- Attributs
Famille d’appareils |
Windows 10 (introduit dans 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduit dans v1.0)
|
Cet exemple montre comment utiliser un délégué DependencyPropertyChangedCallback pour écouter les modifications apportées à la propriété Tag sur un TextBlock.
<TextBlock x:Name="textBlock1" Text="Hello, world"/>
long tagToken;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
long tagToken = textBlock1.RegisterPropertyChangedCallback(TextBlock.TagProperty, tbTagChangedCallback);
base.OnNavigatedTo(e);
textBlock1.Tag = "name";
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
textBlock1.UnregisterPropertyChangedCallback(TextBlock.TagProperty, tagToken);
base.OnNavigatedFrom(e);
}
private void tbTagChangedCallback(DependencyObject sender, DependencyProperty dp)
{
if (dp == TextBlock.TagProperty)
{
// These lines produce the same result.
System.Diagnostics.Debug.WriteLine("The tag has been set to " + ((TextBlock)sender).Tag);
System.Diagnostics.Debug.WriteLine("The tag has been set to " + sender.GetValue(dp));
}
}
Les valeurs de paramètre du délégué sont basées sur le paramètre donné à l’appel RegisterPropertyChangedCallback qui a inscrit une propriété particulière pour la notification de modification de propriété, et sur l’instance qui l’a appelée.
Étant donné que le rappel a le paramètre dp qui identifie la valeur de propriété modifiée, vous pouvez utiliser le même rappel pour gérer plusieurs cas de modification de propriété, et votre logique peut écrire des cas pour chaque propriété différente.
Pour des raisons de performances, vous n’obtenez pas de paire de propriétés OldValue / NewValue à partir d’une méthode PropertyChangedCallback comme vous le faites à partir de DependencyPropertyChangedEventArgs. La valeur de la propriété étant modifiée avant le rappel, une fois la méthode appelée, vous pouvez appeler DependencyObject.GetValue pour récupérer la nouvelle valeur.
Produit | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |