Share via


Événement ItemConstraint

Se produit lorsqu'un conflit de contraintes est signalé, pour les conflits de contraintes de collision lorsque la stratégie de résolution de conflit de collision a la valeur ApplicationDefined, ainsi que pour tous les conflits de contraintes de non-collision.

Espace de noms :  Microsoft.Synchronization
Assembly :  Microsoft.Synchronization (dans Microsoft.Synchronization.dll)

Syntaxe

'Déclaration
Public Event ItemConstraint As EventHandler(Of ItemConstraintEventArgs)
'Utilisation
Dim instance As SyncCallbacks
Dim handler As EventHandler(Of ItemConstraintEventArgs)

AddHandler instance.ItemConstraint, handler
public event EventHandler<ItemConstraintEventArgs> ItemConstraint
public:
 event EventHandler<ItemConstraintEventArgs^>^ ItemConstraint {
    void add (EventHandler<ItemConstraintEventArgs^>^ value);
    void remove (EventHandler<ItemConstraintEventArgs^>^ value);
}
member ItemConstraint : IEvent<EventHandler<ItemConstraintEventArgs>,
    ItemConstraintEventArgs>

Notes

Cette notification peut être utilisée par une application pour effectuer une résolution de conflit personnalisée pour les conflits de contraintes. Pour ce faire, l'application examine et traite le contenu de l'objet ItemConstraintEventArgs qui est envoyé au gestionnaire d'événements, puis définit l'action de résolution pour le conflit en appelant SetResolutionAction avant qu'il soit retourné à partir de cette méthode.

Lorsque la valeur affectée à la propriété ConstraintConflictReason de l'objet ItemConstraintEventArgs est toute valeur autre que Collision, l'action de résolution doit avoir la valeur SkipChange ou SaveConflict.

Exemples

L'exemple suivant implémente un gestionnaire pour l'événement ItemConstraint. Le gestionnaire affiche les éléments en conflit à l'intention de l'utilisateur et définit l'action de résolution de conflit de contraintes en fonction de la réponse de l'utilisateur.

Private Sub HandleItemConstraint(ByVal sender As [Object], ByVal args As ItemConstraintEventArgs)
    If ConstraintConflictReason.Collision = args.ConstraintConflictReason Then
        ' Display the two items that are in conflict and solicit a resolution from the user.
        Dim srcContact As New Contact(DirectCast(args.SourceChangeData, String()))
        Dim destContact As New Contact(DirectCast(args.DestinationChangeData, String()))
        Dim msg As String = ("Source change is " & srcContact.ToString() & vbLf & "Destination change is ") & destContact.ToString() & vbLf & "Click Yes to rename the source change and apply it." & vbLf & "Click No to rename the destination item and apply the source change." & vbLf & "Click Cancel to delete the destination item and apply the source change."
        Dim ccDlg As New ConstraintConflictDlg(msg)
        ccDlg.ShowDialog()

        ' Set the resolution action based on the user's response.
        args.SetResolutionAction(ccDlg.Resolution)
    Else
        args.SetResolutionAction(ConstraintConflictResolutionAction.SaveConflict)
    End If
End Sub
void HandleItemConstraint(Object sender, ItemConstraintEventArgs args)
{
    if (ConstraintConflictReason.Collision == args.ConstraintConflictReason)
    {
        // Display the two items that are in conflict and solicit a resolution from the user.
        Contact srcContact = new Contact((string[])args.SourceChangeData);
        Contact destContact = new Contact((string[])args.DestinationChangeData);
        string msg = "Source change is " + srcContact.ToString() +
                   "\nDestination change is " + destContact.ToString() +
                   "\nClick Yes to rename the source change and apply it." +
                   "\nClick No to rename the destination item and apply the source change." +
                   "\nClick Cancel to delete the destination item and apply the source change.";
        ConstraintConflictDlg ccDlg = new ConstraintConflictDlg(msg);
        ccDlg.ShowDialog();

        // Set the resolution action based on the user's response.
        args.SetResolutionAction(ccDlg.Resolution);
    }
    else 
    {
        args.SetResolutionAction(ConstraintConflictResolutionAction.SaveConflict);
    }
}

Voir aussi

Référence

SyncCallbacks Classe

Membres SyncCallbacks

Espace de noms Microsoft.Synchronization

Autres ressources

Détection et résolution des conflits de contraintes