资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何进行WF4属性窗格PropertyGrid扩展

今天就跟大家聊聊有关如何进行WF4属性窗格PropertyGrid扩展,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司成立于2013年,先为城西等服务建站,城西等地企业,进行企业商务咨询服务。为城西企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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

namespace CaryPropertyGridExten  {      public sealed class CaryActivity : CodeActivity      {                  public InArgument Text { get; set; }          public double RepeatCount { get; set; }         public string FileName { get; set; }                     protected override void Execute(CodeActivityContext context)          {                                 }      }  }

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

如何进行WF4属性窗格PropertyGrid扩展

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

namespace CaryPropertyGridExten  {      class CustomInlineEditor : PropertyValueEditor
  •     {   

  •         public CustomInlineEditor()  

  •         {  

  •             this.InlineEditorTemplate = new DataTemplate();   

  •             FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));  

  •             FrameworkElementFactory slider = new FrameworkElementFactory(typeof(Slider));  

  •             Binding sliderBinding = new Binding("Value");  

  •             sliderBinding.Mode = BindingMode.TwoWay;  

  •             slider.SetValue(Slider.MinimumProperty, 0.0);  

  •             slider.SetValue(Slider.MaximumProperty, 100.0);  

  •             slider.SetValue(Slider.ValueProperty, sliderBinding);  

  •             stack.AppendChild(slider);  

  •             FrameworkElementFactory textb = new FrameworkElementFactory(typeof(TextBox));  

  •             Binding textBinding = new Binding("Value");  

  •             textb.SetValue(TextBox.TextProperty, textBinding);  

  •             textb.SetValue(TextBox.IsEnabledProperty, false);  

  •             stack.AppendChild(textb);  

  •             this.InlineEditorTemplate.VisualTree = stack;  

  •         }  

  •     }  

  • }  

  • namespace CaryPropertyGridExten  

  • {  

  •     class FilePickerEditor : DialogPropertyValueEditor  

  •     {  

  •         public FilePickerEditor()  

  •         {  

  •             this.InlineEditorTemplate = new DataTemplate();   

  •             FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));  

  •             stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);  

  •             FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));  

  •             Binding labelBinding = new Binding("Value");  

  •             label.SetValue(Label.ContentProperty, labelBinding);  

  •             label.SetValue(Label.MaxWidthProperty, 90.0);  

  •             stack.AppendChild(label);  

  •             FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));  

  •             editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);  

  •             stack.AppendChild(editModeSwitch);  

  •             this.InlineEditorTemplate.VisualTree = stack;  

  •         }  

  •         public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)  

  •         {  

  •             Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();  

  •             if (ofd.ShowDialog() == true)  

  •             {  

  •                 propertyValue.Value = ofd.FileName.Substring(ofd.FileName.LastIndexOf('\\') + 1);  

  •             }  

  •         }  

  •     }  

  • }  

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

    public CaryActivity()        {            AttributeTableBuilder builder = new AttributeTableBuilder();
  •           builder.AddCustomAttributes(typeof(CaryActivity), "RepeatCount", new EditorAttribute(typeof(CustomInlineEditor), typeof(PropertyValueEditor)));  

  •           builder.AddCustomAttributes(typeof(CaryActivity), "FileName", new EditorAttribute(typeof(FilePickerEditor), typeof(DialogPropertyValueEditor)));  

  •           MetadataStore.AddAttributeTable(builder.CreateTable());  

  •       }    

看完上述内容,你们对如何进行WF4属性窗格PropertyGrid扩展有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


本文名称:如何进行WF4属性窗格PropertyGrid扩展
文章源于:http://cdkjz.cn/article/gcepij.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220