WF4:属性窗格PropertyGrid扩展

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

namespace CaryPropertyGridExten

{

    public sealed class CaryActivity : CodeActivity

    {       

        public InArgument<string> Text { getset; }

        public double RepeatCount { getset; }

        public string FileName { getset; }          

        protected override void Execute(CodeActivityContext context)

        {                      

        }

    }

}

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

clip_image002

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的构造函数中增加自定义属性的信息如下,关于AttributeTableBuilderMetadataStore的使用可参考关于元数据存储区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());

        }  

 

例子来源:WF_WCF_Samples


本文转自生鱼片博客园博客,原文链接:http://www.cnblogs.com/carysun/archive/2009/11/30/WF4-PropertyGridExten.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值