c# - 添加另一个下拉按钮到自己的 devexpress PopupContainerEdit 具有相同的样式行为

标签 c# devexpress devexpress-windows-ui

我们已经有了继承自 DevExpress 的 PopupContainerEdit 的自定义 PopupContainerEdit。我们的自定义功能之一是另一个下拉按钮(EditorButton with kind = ButtonPredefines.Glyph),其行为与默认按钮类似,只是它会打开不同的 PopupContainerControl >。除了按钮的样式着色之外,一切都按预期工作。该按钮的作用类似于默认按钮 - 这意味着当下拉列表可见/隐藏时,它不支持状态着色(选中/未选中)。我找不到 EditorButton 的任何自定义绘制事件/方法。

有可能实现这样的行为吗?如果是这样,怎么办?

@编辑

Example

上述情况的简单示例。

  • 默认 PopupContainerEdit 看起来像图像 A。当您单击 按钮(类似三角形),下拉菜单显示并且按钮进入选中状态 状态。
  • 我们的 PopupContainerEdit (从默认继承)看起来像 B、
  • C、D 是悬停按钮时的着色示例。<​​/li>
  • E 是默认按钮的选中状态颜色(其工作方式类似于 DevExpress 的设计)。
  • F 是我们的按钮行为 - 就像普通按钮一样。
  • G 是我们想要的 - 按钮的选中状态颜色

我们创建自定义按钮的方法:

string TheToolTipText = "The text";
string OurButtonTag = "TheButton";
Image TheIcon = new Image(); // just example ...

EditorButton customButton = new EditorButton();
customButton.Width = 16;
customButton.Image = TheIcon;
customButton.ToolTip = TheToolTipText;
customButton.Tag = OurButtonTag;
customButton.Kind = ButtonPredefines.Glyph;
this.Properties.Buttons.Add(customButton);

说实话,没有什么可展示的了。我们不知道有任何自定义绘制事件或类似的事情。

最佳答案

RepositoryItemPopupContainerEdit 中有两个属性负责此行为。第一个是RepositoryItemPopupBase.ActionButtonIndex属性(property)。它的值指定哪个编辑器按钮将打开编辑器的下拉窗口。第二个是RepositoryItemPopupContainerEdit.PopupControl设置要在弹出窗口中显示的控件。因此,通过操纵这两个属性,您可以实现所需的行为。

这里是示例:

<强>0。 RepositoryItemPopupContainerEdit 后代

因为你需要显示两个不同的PopupContainerControl 您可以为自定义 RepositoryItem 中的每个控件创建其他属性。

public class RepositoryItemCustomEdit1 : RepositoryItemPopupContainerEdit
{
    #region Some default stuff for custom repository item (constructors, registration, etc).
    static RepositoryItemCustomEdit1() { RegisterCustomEdit1(); }
    public const string CustomEditName = "CustomEdit1";
    public RepositoryItemCustomEdit1() { }
    public override string EditorTypeName { get { return CustomEditName; } }
    public static void RegisterCustomEdit1()
    {
        Image img = null;
        EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(
            CustomEditName, 
            typeof(CustomEdit1), 
            typeof(RepositoryItemCustomEdit1),
        //For v13.2 you need to use custom ViewInfo class. So, here is CustomEdit1ViewInfo.
        //For v15.1 you can use the base PopupContainerEditViewInfo.
            typeof(CustomEdit1ViewInfo),
            new ButtonEditPainter(), 
            true, 
            img));
    }
    #endregion

    #region Hide base PopupContainerControl properties in designer.
    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public override PopupContainerControl PopupControl
    {
        get { return base.PopupControl; }
        set { base.PopupControl = value; }
    }

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public override int ActionButtonIndex
    {
        get { return base.ActionButtonIndex; }
        set { base.ActionButtonIndex = value; }
    }
    #region

    #region First PopupContainerControl properties
    public int DefaultActionButtonIndex { get; set; }
    public PopupContainerControl DefaultPopupControl { get; set; }
    #endregion

    #region Another PopupContainerControl properties
    public int DifferentActionButtonIndex { get; set; }
    public PopupContainerControl DifferentPopupControl { get; set; }
    #endregion

    public override void Assign(RepositoryItem item)
    {
        BeginUpdate();
        try
        {
            base.Assign(item);
            RepositoryItemCustomEdit1 source = item as RepositoryItemCustomEdit1;
            if (source == null) return;

            DefaultActionButtonIndex = source.DefaultActionButtonIndex;
            DefaultPopupControl = source.DefaultPopupControl;

            DifferentPopupControl = source.DifferentPopupControl;
            DifferentActionButtonIndex = source.DifferentActionButtonIndex;
        }
        finally
        {
            EndUpdate();
        }
    }
}

您可以在设计器中看到新属性:
Designer

<强>1。 PopupContainerEdit 后代

现在您可以在自定义 Edit 类中使用此属性。

public class CustomEdit1 : PopupContainerEdit
{
    #region Some default stuff for custom edit (constructors, registration, etc).
    static CustomEdit1() { RepositoryItemCustomEdit1.RegisterCustomEdit1(); }
    public CustomEdit1() { }
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public new RepositoryItemCustomEdit1 Properties { get { return base.Properties as RepositoryItemCustomEdit1; } }
    public override string EditorTypeName { get { return RepositoryItemCustomEdit1.CustomEditName; } }
    #endregion

    protected override bool IsActionButton(EditorButtonObjectInfoArgs buttonInfo)
    {
        int buttonIndex = Properties.Buttons.IndexOf(buttonInfo.Button);

        if (buttonIndex == Properties.DefaultActionButtonIndex ||
            buttonIndex == Properties.DifferentActionButtonIndex)
        {
            //Set the Properties.ActionButtonIndex value according to which button is pressed:
            Properties.ActionButtonIndex = buttonIndex;

            //Set the Properties.PopupControl according to which button is pressed:
            if (buttonIndex == Properties.DefaultActionButtonIndex)
                Properties.PopupControl = Properties.DefaultPopupControl;
            else
                Properties.PopupControl = Properties.DifferentPopupControl;

            return true;
        }

        return false;                
    }
}

<强>2。 PopupContainerEditViewInfo 后代

对于 v13.2,您需要为编辑器使用自定义 ViewInfo 类:

public class CustomEdit1ViewInfo : PopupContainerEditViewInfo
{
    public CustomEdit1ViewInfo(RepositoryItem item) : base(item) { }

    public new RepositoryItemPopupBase Item { get { return base.Item as RepositoryItemCustomEdit1; } }

    //Show the pressed state when button is pressed or when popup is open.
    protected override bool IsButtonPressed(EditorButtonObjectInfoArgs info)
    {
        var hitObject = PressedInfo.HitObject as EditorButtonObjectInfoArgs;

        return
            (hitObject != null && hitObject.Button == info.Button) ||
            (IsPopupOpen && Item.ActionButtonIndex == info.Button.Index);
    }
}

结果

在结果中你会得到这样的结果:

DefaultPopupControlDifferentPopupControl

关于c# - 添加另一个下拉按钮到自己的 devexpress PopupContainerEdit 具有相同的样式行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33214517/

相关文章:

c# - 从结构数组填充组合框

c# - 安全网络服务器 asp.net

delphi - Delphi XE 中的 Ansi TStringList 用于非 Unicode 兼容性

c# - 将 devexpress xtrareports 中两个标签的值相加

c - 在 DevExpress vb.net 中使用 CheckBoxList 分配和评估?

c# - 测试泛型方法参数是否为类

c# - 字符串参数太长。从数据库中检索数据到word模板

c# - 在 DevExpress eXpressApp Framework (XAF) 应用程序中获取导航项

DevExpress XtraGrid RepositoryItemButtonEdit 事件未触发