共用方式為


SyncCallbacks.ItemConstraint 事件

在報告條件約束衝突時發生,代表衝突解決原則設定為 ApplicationDefined 時發生的衝突,以及所有非衝突條件約束衝突。

命名空間: Microsoft.Synchronization
組件: Microsoft.Synchronization (在 microsoft.synchronization.dll)

語法

'宣告
Public Event ItemConstraint As EventHandler(Of ItemConstraintEventArgs)
'用途
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);
}
/** @event */
public void add_ItemConstraint (EventHandler<ItemConstraintEventArgs> value)

/** @event */
public void remove_ItemConstraint (EventHandler<ItemConstraintEventArgs> value)
JScript supports the use of events, but not the declaration of new ones.

備註

應用程式可以使用這項通知來執行條件約束衝突的自訂衝突解決方法。為了完成這項作業,應用程式會檢查並處理傳送至事件處理常式之 ItemConstraintEventArgs 物件的內容,然後在這個方法傳回之前,透過呼叫 SetResolutionAction 設定衝突的解決動作。

ItemConstraintEventArgs 物件的 ConstraintConflictReason 屬性設定為 Collision 以外的任何值時,解決動作必須設定為 SkipChangeSaveConflict

範例

下列範例會實作 ItemConstraint 事件的處理常式。此處理常式會向使用者顯示衝突項目,並且根據使用者的回應設定條件約束衝突解決動作。

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);
    }
}

請參閱

參考

SyncCallbacks 類別
SyncCallbacks 成員
Microsoft.Synchronization 命名空間

概念

偵測及解決條件約束衝突