源代码下载:http://www.shareidea.net/opensource.htm
在线演示:http://www.shareidea.net/workflow.htm
视频教程: http://www.shareidea.net/video/sharedesigner/sharedesigner.html
本文系列索引:
使用silverlight构建一个工作流设计器(一)
使用silverlight构建一个工作流设计器(二)
使用silverlight构建一个工作流设计器(三)
使用silverlight构建一个工作流设计器(四)
使用silverlight构建一个工作流设计器(五)
使用silverlight构建一个工作流设计器(六)
使用silverlight构建一个工作流设计器(七)
使用silverlight构建一个工作流设计器(八)
使用silverlight构建一个工作流设计器(九)
使用silverlight构建一个工作流设计器(十)
使用silverlight构建一个工作流设计器(十一)
本章包含以下内容:
l 规则曲线支持两个中间点的移动
l 双击规则中间点,自定对齐曲线
l 增加选定活动的左右、上下对齐功能
六、增强的用户体验功能 6.8规则曲线支持两个中间点的移动
在前面的规则图形中,也支持曲线类型的线条,但是线条的转折点是自动生成的,根据网友的反馈,希望增加可以用户自己移动的转折点,效果图如下:
为了使得程序清晰,更加面向对象,对于转折点我们使用一个单独的类(用户控件)来表示,这个转折点类只包含一个圆(Ellipse)。Xmal代码如下:
Code
<UserControl x:Class="ShareIDea.Web.UI.Control.Workflow.Designer.RuleTurnPoint"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Canvas>
<Canvas.Resources>
<Storyboard x:name="sbdisplay">
<DoubleAnimation From="0" To="0.8" Duration="00:00:1.0"
Storyboard.Targetname="eliTurnPoint"
Storyboard.TargetProperty="Opacity" >
</DoubleAnimation>
</Storyboard>
<Storyboard x:name="sbColse">
<DoubleAnimation From="0.8" To="0.0" Duration="00:00:1.0"
Storyboard.Targetname="eliTurnPoint"
Storyboard.TargetProperty="Opacity" >
</DoubleAnimation>
</Storyboard>
</Canvas.Resources>
<Ellipse name="eliTurnPoint" WIDth="8" Height="8" Fill="Green" Opacity="0.8"
MouseleftbuttonDown="Canvas_MouseleftbuttonDown"
MouseleftbuttonUp="Canvas_MouseleftbuttonUp"
MouseMove="Canvas_MouseMove"
></Ellipse>
</Canvas>
</UserControl>
转折点是动态增加到规则类中的,转折点向外暴露两个事件。
l 转折点拖拽移动事件:当转折点被鼠标拖拽移动时,需要重新设置规则的直线坐标点。
l 转折点双击事件:当双击转折点时,需要重新设定规则的直线坐标,自动对其线段。
转折点包含两个重要的属性:
l Radius:转折点图形的半径。
l Centerposition:转折点的中心坐标(相对Canvas的坐标 )。
下面是转折点类的代码:
Codepublic partial class RuleTurnPoint : UserControl
{
public delegate voID RuleTurnPointMoveDelegate(object sender, MouseEventArgs e, Point newPoint);
public delegate voID DoubleClickDelegate(object sender, EventArgs e);
public event RuleTurnPointMoveDelegate RuleTurnPointMove;
public RuleTurnPoint()
{
InitializeComponent();
_doubleClickTimer = new System.windows.Threading.dispatcherTimer();
_doubleClickTimer.Interval = new TimeSpan(0, 0, 200);
_doubleClickTimer.Tick += new EventHandler(_doubleClickTimer_Tick);
}
voID _doubleClickTimer_Tick(object sender, EventArgs e)
{
_doubleClickTimer.Stop();
}
public Brush Fill
{
get
{
return eliTurnPoint.Fill;
}
set
{
eliTurnPoint.Fill = value;
}
}
public voID Showdisplayautomation()
{
sbdisplay.Begin();
}
public voID ShowCloseautomation()
{
sbColse.Begin();
}
private voID Canvas_MouseEnter(object sender, MouseEventArgs e)
{
}
Point mouseposition;
bool trackingMouseMove = false;
bool hadActualMove = false;
System.windows.Threading.dispatcherTimer _doubleClickTimer;
public event DoubleClickDelegate ondoubleclick;
private voID Canvas_MouseleftbuttonDown(object sender, MousebuttonEventArgs e)
{
e.Handled = true;
if (_doubleClickTimer.IsEnabled)
{
_doubleClickTimer.Stop();
if (ondoubleclick != null)
ondoubleclick(this, e);
}
else
{
_doubleClickTimer.Start();
FrameworkElement element = sender as FrameworkElement;
mouseposition = e.Getposition(null);
trackingMouseMove = true;
hadActualMove = false;
if (null != element)
{
element.CaptureMouse();
element.Cursor = Cursors.Hand;
}
}
}
private voID Canvas_MouseleftbuttonUp(object sender, MousebuttonEventArgs e)
{
e.Handled = true;
FrameworkElement element = sender as FrameworkElement;
hadActualMove = false;
trackingMouseMove = false;
element.ReleaseMouseCapture();
mouseposition = e.Getposition(null);
element.Cursor = null;
}
public double Radius
{
get
{
return eliTurnPoint.WIDth / 2;
}
}
public Point Centerposition {
get
{
return new Point((double)this.GetValue(Canvas.leftProperty) + Radius, (double)this.GetValue(Canvas.topProperty) + Radius);
}
set
{
this.SetValue(Canvas.leftProperty, value.X - Radius);
this.SetValue(Canvas.topProperty, value.Y - Radius);
}
}
private voID Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (trackingMouseMove)
{
FrameworkElement element = sender as FrameworkElement;
element.Cursor = Cursors.Hand;
if (e.Getposition(null) == mouseposition)
return;
hadActualMove = true;
double deltaV = e.Getposition(null).Y - mouseposition.Y;
double deltaH = e.Getposition(null).X - mouseposition.X;
double newtop = deltaV + Centerposition.Y;
double newleft = deltaH + Centerposition.X;
Point p = new Point(newleft, newtop);
Centerposition = p;
if (RuleTurnPointMove != null)
{
RuleTurnPointMove(sender, e,p);
}
mouseposition = e.Getposition(null);
}
}
}
6.9 活动对齐功能
对于选中的活动,可以按照下面4种方式对齐:
l 向左对齐:选中活动的X坐标设置为其中X坐标最小的值。
l 向右对齐:选中活动的X坐标设置为其中X坐标最大的值。
l 向上对齐:选中活动的Y坐标设置为其中X坐标最小的值。
l 向下对齐:选中活动的Y坐标设置为其中X坐标最大的值。
为了需要两次遍历选中的活动集合。第一次遍历取得其中X/Y坐标的最小/最大值,第二次遍历设置活动的X/Y坐标为最小/最大值。
代码如下所示:
Code
public voID Aligntop()
{
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
return;
Activity a = null;
double minY = 100000.0;
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
if (a.CenterPoint.Y < minY)
minY = a.CenterPoint.Y;
}
}
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
a.CenterPoint = new Point(a.CenterPoint.X, minY);
}
}
}
public voID AlignBottom()
{
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
return;
Activity a = null;
double maxY = 0;
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
if (a.CenterPoint.Y >maxY)
maxY = a.CenterPoint.Y;
}
}
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
a.CenterPoint = new Point(a.CenterPoint.X, maxY);
}
}
}
public voID Alignleft()
{
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
return;
Activity a = null;
double minX = 100000.0;
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
if (a.CenterPoint.X < minX)
minX = a.CenterPoint.X;
}
}
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
a.CenterPoint = new Point(minX, a.CenterPoint.Y);
}
}
}
public voID AlignRight()
{
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
return;
Activity a = null;
double maxX = 0;
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
if (a.CenterPoint.X > maxX)
maxX = a.CenterPoint.X;
}
}
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
{
if (CurrentSelectedControlCollection[i] is Activity)
{
a = CurrentSelectedControlCollection[i] as Activity;
a.CenterPoint = new Point(maxX, a.CenterPoint.Y); } } } 总结
以上是内存溢出为你收集整理的使用silverlight构建一个工作流设计器(十一)(附源代码下载、在线演示、视频教程)全部内容,希望文章能够帮你解决使用silverlight构建一个工作流设计器(十一)(附源代码下载、在线演示、视频教程)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)