浅析WF4属性窗格PropertyGrid扩展
创始人
2024-06-13 09:00:15
0

本文将讲解的是WF4属性窗格PropertyGrid扩展,希望对大家了解Windows Workflow Foundation框架有所帮助。

#T#

1.       我们有一个CaryActivity活动如下:

  1. namespace CaryPropertyGridExten  
  2. {  
  3.     public sealed class CaryActivity : CodeActivity  
  4.     {          
  5.         public InArgument Text { get; set; }  
  6.         public double RepeatCount { get; set; }  
  7.        public string FileName { get; set; }             
  8.         protected override void Execute(CodeActivityContext context)  
  9.         {                         
  10.         }  
  11.     }  

2.       上面活动有RepeatCount和FileName属性,我们会为这两个属性在属性窗格的设置自定义属性值编辑器,要达到效果如下图:

效果图

3.       分别定义两个属性对应的属性值编辑器如下:

  1. namespace CaryPropertyGridExten  
  2. {  
  3.     class CustomInlineEditor : PropertyValueEditor  
  4.     {   
  5.         public CustomInlineEditor()  
  6.         {  
  7.             this.InlineEditorTemplate = new DataTemplate();   
  8.             FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));  
  9.             FrameworkElementFactory slider = new FrameworkElementFactory(typeof(Slider));  
  10.             Binding sliderBinding = new Binding("Value");  
  11.             sliderBinding.Mode = BindingMode.TwoWay;  
  12.             slider.SetValue(Slider.MinimumProperty, 0.0);  
  13.             slider.SetValue(Slider.MaximumProperty, 100.0);  
  14.             slider.SetValue(Slider.ValueProperty, sliderBinding);  
  15.             stack.AppendChild(slider);  
  16.             FrameworkElementFactory textb = new FrameworkElementFactory(typeof(TextBox));  
  17.             Binding textBinding = new Binding("Value");  
  18.             textb.SetValue(TextBox.TextProperty, textBinding);  
  19.             textb.SetValue(TextBox.IsEnabledProperty, false);  
  20.             stack.AppendChild(textb);  
  21.             this.InlineEditorTemplate.VisualTree = stack;  
  22.         }  
  23.     }  
  24. }  
  25. namespace CaryPropertyGridExten  
  26. {  
  27.     class FilePickerEditor : DialogPropertyValueEditor  
  28.     {  
  29.         public FilePickerEditor()  
  30.         {  
  31.             this.InlineEditorTemplate = new DataTemplate();   
  32.             FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));  
  33.             stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);  
  34.             FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));  
  35.             Binding labelBinding = new Binding("Value");  
  36.             label.SetValue(Label.ContentProperty, labelBinding);  
  37.             label.SetValue(Label.MaxWidthProperty, 90.0);  
  38.             stack.AppendChild(label);  
  39.             FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));  
  40.             editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);  
  41.             stack.AppendChild(editModeSwitch);  
  42.             this.InlineEditorTemplate.VisualTree = stack;  
  43.         }  
  44.         public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)  
  45.         {  
  46.             Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();  
  47.             if (ofd.ShowDialog() == true)  
  48.             {  
  49.                 propertyValue.Value = ofd.FileName.Substring(ofd.FileName.LastIndexOf('\\') + 1);  
  50.             }  
  51.         }  
  52.     }  
  53. }  

4.       在CaryActivity的构造函数中增加自定义属性的信息如下,关于AttributeTableBuilder及MetadataStore的使用可参考关于元数据存储区MetadateStore及AttributeTableBuilder这篇文章。

  1. public CaryActivity()  
  2.       {  
  3.           AttributeTableBuilder builder = new AttributeTableBuilder();  
  4.           builder.AddCustomAttributes(typeof(CaryActivity), "RepeatCount"new EditorAttribute(typeof(CustomInlineEditor), typeof(PropertyValueEditor)));  
  5.           builder.AddCustomAttributes(typeof(CaryActivity), "FileName"new EditorAttribute(typeof(FilePickerEditor), typeof(DialogPropertyValueEditor)));  
  6.           MetadataStore.AddAttributeTable(builder.CreateTable());  
  7.       }    

原文标题:WF4:属性窗格PropertyGrid扩展

链接:http://www.cnblogs.com/carysun/archive/2009/11/30/WF4-PropertyGridExten.html

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...