工作流程活动

发布于 2024-08-11 18:59:11 字数 115 浏览 10 评论 0原文

假设我有一个自定义活动,它具有 GUID 类型的依赖属性。

我希望在我的自定义设计器中显示一个组合框(或我自己的用户控件),其中包含可供选择的可能值(这些值应来自数据库)。

这可能吗?

Let's say I have a custom activity that has a dependency property of type GUID.

I want in my custom designer to show like a combobox (or my own usercontrol) with possible values to select from (the values should comes from the database).

Is this possible ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉南桥 2024-08-18 18:59:11

您需要创建一个UITypeEditor。以下是组合框编辑器的模板:-

public class MyCustomEditor : UITypeEditor
{
  public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  {
    return UITypeEditorEditStyle.DropDown;
  }
  public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider)
  {
    var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
    var list = new ListBox();

    // Your code here to populate the list box with your items

    EventHandler onclick = (sender, e) => {
      editiorService.CloseDropDown();
    };

    list.Click += onclick;

    myEditorService.DropDownControl(list);

    list.Click -= onclick;

    return (list.SelectedItem != null) ? list.SelectedItem : Guid.Empty;
  }
}

在活动中的属性上:-

[Editor(typeof(MyCustomEditor), typeof(UITypeEditor)]
public Guid MyGuidValue
{
    get { return (Guid)GetValue(MyGuidValueProperty); }
    set { SetValue(MyGuidValueProperty, value); }
}
  • Editor 属性将告诉 PropertyGrid 您已为此属性创建了自定义编辑器。
  • 编辑器的 GetEditStyle 方法告诉属性网格在属性值上显示一个下拉按钮。
  • 单击时,属性网格将调用自定义编辑器的 EditValue 方法。
  • 编辑器服务用于通过 DropDownControl 方法显示下拉菜单,该方法采用要在下拉区域中显示的控件。
  • DropDownControl 方法将阻塞,直到调用编辑器服务 CloseDropDown 方法。

You need to create a UITypeEditor. The following is a template for a combox editor:-

public class MyCustomEditor : UITypeEditor
{
  public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  {
    return UITypeEditorEditStyle.DropDown;
  }
  public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider)
  {
    var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
    var list = new ListBox();

    // Your code here to populate the list box with your items

    EventHandler onclick = (sender, e) => {
      editiorService.CloseDropDown();
    };

    list.Click += onclick;

    myEditorService.DropDownControl(list);

    list.Click -= onclick;

    return (list.SelectedItem != null) ? list.SelectedItem : Guid.Empty;
  }
}

On your property in the activity:-

[Editor(typeof(MyCustomEditor), typeof(UITypeEditor)]
public Guid MyGuidValue
{
    get { return (Guid)GetValue(MyGuidValueProperty); }
    set { SetValue(MyGuidValueProperty, value); }
}
  • The Editor attribute will tell the PropertyGrid that you have created a custom editor for this property.
  • The GetEditStyle method of the Editor tells the property grid to display a drop down button on the propery value.
  • When clicked the property grid calls the custom editor's EditValue method.
  • The editor service is used to display a drop down with the DropDownControl method which takes a control that is to be display in the drop down area.
  • The DropDownControl method will block until the editor service CloseDropDown method is called.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文