浅析WF4属性窗格PropertyGrid扩展

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

十余年的泰山网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整泰山建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“泰山网站设计”,“泰山网站推广”以来,每个客户项目都认真落实执行。

#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.hantingmc.com/qtweb/news24/533074.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联