你好,我正在使用可以自行嵌套的自定义 WF4 活动。我要捕捉双击事件,所以我重写了 OnPreviewMouseDoubleClick 方法。我的问题是,当活动在另一个活动中并且双击到内部活动时,对它们都调用了双击。我设置了 e.Handled = true 但它不起作用。如何停止在父活动上执行双击事件。
这是我的代码示例:
ActivityDesigner1.xaml
<sap:ActivityDesigner x:Class="ActivityDesignerLibrary1.ActivityDesigner1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
<Grid>
<sap:WorkflowItemsPresenter Items="{Binding Path=ModelItem.Activities}">
<sap:WorkflowItemsPresenter.SpacerTemplate>
<DataTemplate>
<Label HorizontalAlignment="Center" Content="Drop activity here." FontStyle="Italic" Foreground="DarkGray" />
</DataTemplate>
</sap:WorkflowItemsPresenter.SpacerTemplate>
</sap:WorkflowItemsPresenter>
</Grid>
</sap:ActivityDesigner>
ActivityDesigner1.xaml.cs
using System.Windows;
using System.Windows.Input;
namespace ActivityDesignerLibrary1
{
public partial class ActivityDesigner1
{
public ActivityDesigner1()
{
InitializeComponent();
}
protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
{
e.Handled = true;
base.OnPreviewMouseDoubleClick(e);
MessageBox.Show(this.GetHashCode().ToString());
}
}
}
CodeActivity1.cs
using System;
using System.Activities;
using System.Activities.Statements;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace ActivityDesignerLibrary1
{
[Designer(typeof(ActivityDesigner1))]
public sealed class CodeActivity1 : CodeActivity
{
private Sequence innerSequence = new Sequence();
public Collection<Activity> Activities
{
get
{
return this.innerSequence.Activities;
}
}
protected override void Execute(CodeActivityContext context)
{
throw new NotImplementedException();
}
}
}