惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
腾讯CDC
G
Google Developers Blog
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
有赞技术团队
有赞技术团队
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
美团技术团队
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - zhouyongguo

最省力的多语言解决方案 软件的互联网基因 工作流设计图 手机、未来、饭碗 找到最重要的知识 “智能”的随想 软件也是仿生学 软件交互设计原则 把软件做成艺术品 从人脑到搜索引擎的畅想 权限控制和法官判罪 关于程序员的技能 面对各不相同的业务功能的表单系统架构 项目型企业业务模型简单分析 关于软件的交互性设计 关于正规化 知识管理系统模型浅见 软件的世界(1):认识现实世界 - zhouyongguo - 博客园 采用ASP.NET 2.0的Callback机制构建轻量级的AJAX架构
使用Silverlight 实现工作流流程定义
zhouyongguo · 2009-03-01 · via 博客园 - zhouyongguo

Silverlight 是一种跨浏览器、跨平台的 .NET Framework实现。具有如下优势:

  1. 提供一致的体验,而与在何处运行没有关系
  2. 它对视频和音频进行流处理。它将视频品质调整到适合各种环境:从移动设备到桌面浏览器以及 720p HDTV 视频模式
  3. 用户可以直接在浏览器中操作(拖动、旋转和缩放)的足够清晰的2D3D图形

我们可以直接使用它在Web上来完成工作流流程的定义,直接绘制可拉伸,拖放的复杂图形,获得非常好的用户体验。而这在以前只能通过GDI+或者其他并不友好的方法实现。重要的是这一切实现的代码非常简洁。

你需要以下工具来实现:

<!--[if !supportLists]-->1.       <!--[endif]-->Visual Studio 2008

<!--[if !supportLists]-->2.       <!--[endif]-->VS2008SP1

<!--[if !supportLists]-->3.       <!--[endif]-->Silverlight Tools

<!--[if !supportLists]-->4.       <!--[endif]-->Expression Blend2

在完成绘图之前要对Silverlight的绘图平面有详细的了解。

Silverlight提供三个根布局对象来定义整个绘图面,这三个绘图的布局对象皆从Panel 元素的派生,可以实现许多复杂的布局。

Canvas

定义一个区域,在此区域内,您可以使用相对于 Canvas 区域的坐标显式定位子元素。

Grid

定义由行和列组成的灵活网格区域。

StackPanel

将子元素排列成一行(可沿水平或垂直方向)。

此次演练我们将使用Grid元素完成整个页面布局。使用Canvas定义整个可拖放的绘图面,使用StackPanel元素来排列自定义的活动节点用户控件。

 1<Grid x:Name="LayoutRoot" Background="#FF92A4AF" ShowGridLines="True">
 2     <Grid.RowDefinitions>
 3       <RowDefinition Height="40"/>
 4       <RowDefinition Height="400"/>
 5      </Grid.RowDefinitions>
 6     <Grid.ColumnDefinitions>
 7           <ColumnDefinition Width="600"/>
 8     </Grid.ColumnDefinitions>
 9     <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
10      <Button  Width=" 60" Height=" 25" Content="移动" Margin="10"  Click="Button_Click"></Button>
11     <Button  Width=" 60" Height=" 25" Content="连线" Margin="10" Click="Button_Click_1"></Button>
12            <TextBlock x:Name="Status" Foreground="Black"  Text="Status"  Margin="10"  />
13        </StackPanel>
14        <Canvas Height="400" Width="600" x:Name="canver1" Grid.Row="1" Grid.Column="0" Background="#FF92A4AF">         
15    </Canvas>
16        </Grid>


在这过程中主要涉及两个重要的对象

<!--[if !supportLists]-->1.     <!--[endif]-->节点对象 定义工作流的每一个活动,可以显示一个活动的个性图标,名称等等信息,要可以自由拖动,拖动时相关坐标的活动间连线可以自动绘制。

<!--[if !supportLists]-->2.     <!--[endif]-->连线可以自由拉伸的有向折线,终点绘制箭头,绘制过程中实现动态效果,自动粘结节点对象。

使用Blend2绘制节点对象r_2.gif

<StackPanel x:Name="CFlowItem" Background="{x:Null}" >
        
<Border BorderThickness="1,1,1,1"
            Width
="68" Height="41"  x:Name="fItem" CornerRadius="5,5,5,5">
            
<Border.BorderBrush>
                
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" SpreadMethod="Pad">
                    
<GradientStop Color="#FF8C8585" Offset="1"/>
                    
<GradientStop Color="#FFFFFFFF" Offset="0"/>
                
</LinearGradientBrush>
            
</Border.BorderBrush>
            
<Border.Background>
                
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    
<GradientStop Color="#FFEDEEF2"/>
                    
<GradientStop Color="#FF545151" Offset="1"/>                    
                    
<GradientStop Color="#FF999EB6" Offset="0.424"/>
                    
<GradientStop Color="#FFD3D9EB" Offset="0.99099999666213989"/>
                
</LinearGradientBrush>
            
</Border.Background>
            
<Image Source="../images/png-0011.png" Stretch="Fill" Width="35" Height="35" x:Name="img"></Image>
        
</Border>
            
<TextBlock  x:Name="fItemName" Margin="3" Text="审核单据" Width="50" Height="20" Foreground="#FF121111"></TextBlock>
</StackPanel>

以下是节点移动时自动绘制的部分代码

public void Move(Point mousePoint, Point mousePosition)
        {
double deltaV = mousePoint.Y - mousePosition.Y;
            
double deltaH = mousePoint.X - mousePosition.X;
            
double newTop = deltaV + (double)this.GetValue(Canvas.TopProperty);
            
double newLeft =deltaH + (double)this.GetValue(Canvas.LeftProperty);
            
this.SetValue(Canvas.TopProperty, newTop);
            
this.SetValue(Canvas.LeftProperty, newLeft);
            
foreach (PathLine l in list)
            {
                l.DrawPath();
            }
        }

使用Path对象来绘制连线,Silverlight几何图形提供了描绘由弧线、曲线和直线组成的多个复杂图形 如图:


r_4.gif

在实现拖放功能中,分为三个步骤:

1.移动到目标上,选择要拖动的对象

1.按下鼠标,触发MouseLeftButtonDown事件。

2.移动鼠标,触发MouseMove事件,移动选择的对象。

3.放开鼠标,触发MouseLeftButtonUp事件,停止捕捉事件。

Code

o_53.gif

源码:
https://files.cnblogs.com/zhouyongguo/SilverlightApplication1.rar