C# 添加另一个下拉按钮以拥有具有相同样式行为的devexpres PopupContainerEdit
我们有一个自定义的C# 添加另一个下拉按钮以拥有具有相同样式行为的devexpres PopupContainerEdit,c#,devexpress,devexpress-windows-ui,C#,Devexpress,Devexpress Windows Ui,我们有一个自定义的PopupContainerEdit,它继承了DevExpress的PopupContainerEdit。我们的自定义功能之一是另一个下拉按钮(EditorButtonwith kind=ButtonPredefines.Glyph),它与默认按钮类似,只是打开了不同的PopupContainerControl。除了按钮样式的颜色外,一切都按预期进行。该按钮的作用类似于默认按钮-这意味着当下拉列表可见/隐藏时,它不支持状态着色(选中/未选中)。我找不到EditorButton的
PopupContainerEdit
,它继承了DevExpress的PopupContainerEdit
。我们的自定义功能之一是另一个下拉按钮(EditorButton
with kind=ButtonPredefines.Glyph
),它与默认按钮类似,只是打开了不同的PopupContainerControl
。除了按钮样式的颜色外,一切都按预期进行。该按钮的作用类似于默认按钮-这意味着当下拉列表可见/隐藏时,它不支持状态着色(选中/未选中)。我找不到EditorButton
的任何自定义绘图事件/方法
是否有可能实现这种行为?如果是,怎么做
@编辑
上述情况的简单示例
- 默认的
看起来像图像A 按钮(三角形),下拉显示,按钮进入选中状态 国家PopupContainerEdit
- 我们的
(从默认值继承)如下所示 BPopupContainerEdit
- C、 D是悬停按钮时的着色示例
- 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中有两个属性负责此行为。首先是财产。它的值指定哪个编辑器按钮将打开编辑器的下拉窗口。第二个是将控件设置为在弹出窗口中显示。因此,通过使用这两个属性进行操作,可以实现所需的行为 下面是一个例子: 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();
}
}
}
您可以在设计器中看到新属性: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<代码>PopupContainerEdit视图信息后代
对于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);
}
}
结果
结果,您将得到如下结果:
和您可以添加一些代码和图片吗?@nempoBu4添加了一些代码和图像,以说明此变化。中讨论了DevExpress的VCL版本的类似主题。您使用什么DevExpress?我在代码或DE文档中都看不到任何ActionShowPopup方法。你是说ShopPopup吗?@user2475983我的版本是15.1.7。我只是重写受保护的方法。如果在代码中按F12的
PopupContainerEdit
word,然后在PopupBaseEdit
上按F12,则可以找到此方法,然后将看到受保护的虚拟无效操作显示弹出窗口(EditorButtonObjectInfo按钮信息)代码>在popubaseedit
类的其他成员之间。另外,如果您键入override
关键字,则auto complete将在可用方法列表中显示此方法以覆盖。我们的版本是13.2,当我尝试添加override
声明时,列表中不会显示ActionShowPopup等方法。点击F12会将我重定向到刚才添加的方法。@user2475983我已经更新了CustomEdit1
的代码。在v13.2中重写IsActionButton
方法似乎没有问题。试试这个。@user2475983最后,我找到了。同样对于v13.2,您需要使用自定义的ViewInfo
类来检查按钮的按下状态。我已经更新了我的答案。