永利最大(官方)网站

使用silverlight构建一个工作流设计器(十一)(附源代码下载、在线演示、视频教程)

原创|其它|编辑:郝浩|2009-05-21 09:58:29.000|阅读 781 次

概述:本章包含以下内容:规则曲线支持两个中间点的移动。双击规则中间点,自定对齐曲线。增加选定活动的左右、上下对齐功能。

#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>

本章包含以下内容:

l         规则曲线支持两个中间点的移动

l         双击规则中间点,自定对齐曲线

l         增加选定的左右、上下对齐功能

 

六、

6.8曲线支持两个中间点的移动

在前面的规则图形中,也支持曲线类型的线条,但是线条的转折点是自动生成的,根据网友的反馈,希望增加可以用户自己移动的转折点,效果图如下:

为了使得程序清晰,更加面向对象,对于转折点我们使用一个单独的类(用户控件)来表示,这个转折点类只包含一个圆(Ellipse)。Xmal代码如下:

 


<UserControl x:Class="Shareidea.Web.UI.Control.Workflow.Designer.RuleTurnPoint&quot;
    xmlns
="//schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x
="//schemas.microsoft.com/winfx/2006/xaml"    >
    
<Canvas>
        
<Canvas.Resources>
           &nbsp;
<Storyboard  x:Name="sbDisplay">
   ;             
<DoubleAnimation   From="0" To="0.8" Duration="00:00:1.0" 
                    Storyboard.TargetName
="eliTurnPoint" 
&nbsp;                   Storyboard.TargetProperty
="Opacity" >
       &nbsp;        
</DoubleAnimation>
 ;           
</Storyboard>
           
          &nbsp; 
<Storyboard  x:Name="sbColse">
&nbsp;               
<DoubleAnimation   From="0.8" To="0.0" Duration="00:00:1.0" 
              ;      Storyboard.TargetName
="eliTurnPoint" 
            ;        Storyboard.TargetProperty
="Opacity" >
&nbsp;               
</DoubleAnimation>
            
</Storyboard>  
       &nbsp;
</Canvas.Resources>

  ;      
<Ellipse Name="eliTurnPoint" Width="8" Height="8" Fill="Green" Opacity="0.8"
               &nbsp; MouseLeftButtonDown
="Canvas_MouseLeftButtonDown"
    ;    MouseLeftButtonUp
="Canvas_MouseLeftButtonUp"
 &nbsp;      MouseMove
="Canvas_MouseMove"
&nbsp;                
></Ellipse>
    
</Canvas>
</UserControl>

 

 

 

转折点是动态增加到规则类中的,转折点向外暴露两个事件。

l         转折点拖拽移动事件:当转折点被鼠标拖拽移动时,需要重新设置规则的直线坐标点。

l         转折点双击事件:当双击转折点时,需要重新设定规则的直线坐标,自动对其线段。

 

转折点包含两个重要的属性:

l         Radius:转折点图形的半径。

l         CenterPosition:转折点的中心坐标(相对Canvas的坐标 )

 

下面是转折点类的代码:


 public partial class RuleTurnPoint : UserControl
    {
      &nbsp; 
public delegate void RuleTurnPointMoveDelegate(object sender, MouseEventArgs e, Point newPoint);

        
public  delegate void DoubleClickDelegate(object sender, EventArgs e);

 &nbsp;      
public event RuleTurnPointMoveDelegate RuleTurnPointMove;
 &nbsp;      
public RuleTurnPoint()
        {
            InitializeComponent();
            _doubleClickTimer 
= new System.Windows.Threading.DispatcherTimer();
           ; _doubleClickTimer.Interval&nbsp;
= new TimeSpan(0000200);
            _doubleClickTimer.Tick 
+= new EventHandler(_doubleClickTimer_Tick);
        }

    &nbsp;   
void _doubleClickTimer_Tick(object sender, EventArgs e)
        {
            _doubleClickTimer.Stop();
        }
     &nbsp;  
public  Brush Fill
        {
   &nbsp; &nbsp;      
get
            {
           &nbsp;    
return eliTurnPoint.Fill;
            }
     &nbsp;    &nbsp; 
set
            {
       &nbsp;        eliTurnPoint.Fill 
= value;
            }
        }
        ;
public void ShowDisplayAutomation()
        {
            sbDisplay.Begin();
        }
 ;       
public void ShowCloseAutomation()
        {
            sbColse.Begin();
        }

    &nbsp;   
private void Canvas_MouseEnter(object sender, MouseEventArgs e)
        {

        }
        Point mousePosition;
  ;      
bool trackingMouseMove = false;
 &nbsp;      
bool hadActualMove = false;
        System.Windows.Threading.DispatcherTimer _doubleClickTimer;
        
public event DoubleClickDelegate OnDoubleClick;
         
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
&nbsp;           e.Handled 
= true;
    &nbsp;      &nbsp;
if (_doubleClickTimer.IsEnabled)
            {
                _doubleClickTimer.Stop();
            &nbsp;   
if (OnDoubleClick != null)
    ;                OnDoubleClick(
this, e);
            }
           &nbsp;
else
            {
                _doubleClickTimer.Start();
            &nbsp;   FrameworkElement element 
= sender as FrameworkElement;
           &nbsp;    mousePosition 
= e.GetPosition(null);
                trackingMouseMove 
= true;
       &nbsp;        hadActualMove 
= false;
  &nbsp;             
if (null != element)
                {
                    element.CaptureMouse();
            &nbsp;       element.Cursor 
= Cursors.Hand;
                }
            }
        }

        
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
 &nbsp;           e.Handled 
= true;
            FrameworkElement element&nbsp;
= sender as FrameworkElement;
            hadActualMove 
= false;
        &nbsp;   trackingMouseMove 
= false;
            element.ReleaseMouseCapture();
 ;     &nbsp;     mousePosition 
= e.GetPosition(null);
          &nbsp; ;element.Cursor 
= null;
             
        }
&nbsp;       
public double Radius
        {
             
get
            {
 ;          &nbsp;    
return eliTurnPoint.Width / 2;
            }
        }
&nbsp;       
public Point CenterPosition {
          &nbsp; 
get
            {
        &nbsp;       
return new Point((double)this.GetValue(Canvas.LeftProperty) + Radius, (double)this.GetValue(Canvas.TopProperty) + Radius);
            }
       &nbsp;    
set
            {
  &nbsp;           &nbsp; 
this.SetValue(Canvas.LeftProperty, value.X - Radius);
         &nbsp;      
this.SetValue(Canvas.TopProperty, value.Y - Radius);
            }
        }
&nbsp;       
private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            
        ;    
if (trackingMouseMove)
            {
                FrameworkElement&nbsp;element 
= sender as FrameworkElement;
    ;  &nbsp;         element.Cursor 
= Cursors.Hand;

                
if (e.GetPosition(null== mousePosition)
              ;    &nbsp; 
return;
         &nbsp;      hadActualMove 
= true;
              &nbsp; 
double deltaV = e.GetPosition(null).Y - mousePosition.Y;
         &nbsp;      
double deltaH = e.GetPosition(null).X - mousePosition.X;
            &nbsp;   
double newTop = deltaV + CenterPosition.Y;
                
double newLeft = deltaH + CenterPosition.X;

                Point p  
=  new Point(newLeft, newTop);
       ;     ;    CenterPosition 
= p;

              &nbsp; 
if (RuleTurnPointMove != null)
                {
                    RuleTurnPointMove(sender, e,p);
                }
  &nbsp;         &nbsp;   mousePosition 
= e.GetPosition(null);

            }
        }
}

 

6.9

对于选中的活动,可以按照下面4种方式对齐:

l         向左对齐:选中活动的X坐标设置为其中X坐标最小的值。

l         向右对齐:选中活动的X坐标设置为其中X坐标最大的值。

l         向上对齐:选中活动的Y坐标设置为其中X坐标最小的值。

l         向下对齐:选中活动的Y坐标设置为其中X坐标最大的值。

 

为了需要两次遍历选中的活动集合。第一次遍历取得其中X/Y坐标的最小/最大值,第二次遍历设置活动的X/Y坐标为最小/最大值。

代码如下所示:

 


public void AlignTop()
       {
        &nbsp;&nbsp; 
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
    ;         &nbsp; 
return;
    ;       Activity a 
= null;
    &nbsp;      
double minY = 100000.0;
           
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
    &nbsp;  &nbsp;       
if (CurrentSelectedControlCollection[i] is Activity)
               {
                   a 
= CurrentSelectedControlCollection[i] as Activity;

                   
if (a.CenterPoint.Y < minY)
  &nbsp;  ;                  minY 
= a.CenterPoint.Y;
               }


           }
   &nbsp;       
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
               
if (CurrentSelectedControlCollection[i] is Activity)
               {
               &nbsp;   a&nbsp;
= CurrentSelectedControlCollection[i] as Activity;
                    a.CenterPoint 
= new Point(a.CenterPoint.X, minY);
               }


           }
       }
       
public void AlignBottom()
       {
   &nbsp;       
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
             &nbsp; 
return;
         ; &nbsp;Activity a 
= null;
           
double maxY = 0;
        &nbsp;  
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
           &nbsp;   
if (CurrentSelectedControlCollection[i] is Activity)
               {
       &nbsp;           a 
= CurrentSelectedControlCollection[i] as Activity;

              &nbsp;    
if (a.CenterPoint.Y >maxY)
         &nbsp;             maxY 
= a.CenterPoint.Y;
               }


           }
            
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
       ;        
if (CurrentSelectedControlCollection[i] is Activity)
               {
            &nbsp;      a ;
= CurrentSelectedControlCollection[i] as Activity;
      ;             a.CenterPoint 
= new Point(a.CenterPoint.X, maxY);
               }


           }
       }
       
public void AlignLeft()
       {

           
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
             &nbsp; 
return;
&nbsp;          Activity a 
= null;
 ;          
double minX = 100000.0;
          &nbsp;
for (int i = 0; i <&nbsp;CurrentSelectedControlCollection.Count; i++)
           {
       &nbsp;      &nbsp;
if (CurrentSelectedControlCollection[i] is Activity)
               {
                  &nbsp;a 
= CurrentSelectedControlCollection[i] as Activity;

             &nbsp;     
if (a.CenterPoint.X < minX)
      &nbsp;       ;         minX 
= a.CenterPoint.X;
               }


           }
         &nbsp; 
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
 &nbsp;             ;
if (CurrentSelectedControlCollection[i] is Activity)
               {
           &nbsp;       a 
= CurrentSelectedControlCollection[i] as Activity;
     &nbsp;             a.CenterPoint 
= new Point(minX, a.CenterPoint.Y);
               }


           } 

           

       }
       
public void AlignRight()
       {
       &nbsp;  &nbsp;
if (CurrentSelectedControlCollection == null || CurrentSelectedControlCollection.Count == 0)
           &nbsp; &nbsp; 
return;
     &nbsp;     Activity a 
= null;
     ;&nbsp;     
double maxX = 0;
 &nbsp;      &nbsp;  
for (int i = 0; i < CurrentSelectedControlCollection.Count;&nbsp;i++)
           {
   &nbsp;&nbsp;          
if (CurrentSelectedControlCollection[i] is Activity)
               {
                    a&nbsp;
= CurrentSelectedControlCollection[i] as Activity;

  &nbsp; &nbsp;              
if (a.CenterPoint.X > maxX)
  ;           &nbsp;         maxX 
= a.CenterPoint.X;
               }


           }
           
for (int i = 0; i < CurrentSelectedControlCollection.Count; i++)
           {
      &nbsp;        
if (CurrentSelectedControlCollection[i] is Activity)
               {
                   a&nbsp;
= CurrentSelectedControlCollection[i] as Activity;
    &nbsp;              a.CenterPoint 
= new Point(maxX, a.CenterPoint.Y);
               }


           }
       }

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@hmdbvip.cn

文章转载自:博客园

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP
PM娱乐城网络现金网站(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) PM娱乐城最大(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) 永利外围最新(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) 网络权威朗驰娱乐大全(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) 永利真人网上足球(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) 利记最火十大网(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) boyu·博鱼权威网络足球(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新) PM娱乐城网上足球(官方)网站/网页版登录入口/手机版登录入口-最新版(已更新)