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 之外的任何值时,必须将解决操作设置为 SkipChange 或 SaveConflict。
示例
下面的示例实现 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 命名空间