简体   繁体   English

PropertyGrid不适用于选择颜色

[英]PropertyGrid does not work for picking a color

I have a class that I am viewing with a property grid with the following property: 我有一个正在查看的类,该类具有以下属性:

private Color _borderColor = Color.Black;
[Browsable(true)]
[Category("Appearance")]
[DisplayName("Border Color")]
[Description("The color of the border.")]
[DefaultValue(typeof(Color), "Black")]
public virtual Color BorderColor
{
    get
    {
        return _borderColor;
    }
    set
    {
        if (_borderColor != value)
        {
            _borderColor = value;

            Invalidate();
        }
    }
}

I am having various intermittent problems changing this property using the property grid. 我在使用属性网格更改此属性时遇到各种间歇性问题。

Initially, I am able to open the drop-down popup. 最初,我能够打开下拉菜单。 But when I pick a color it doesn't change the property. 但是,当我选择一种颜色时,它不会改变属性。 When debugging, it does not even call the "set" accessor. 调试时,它甚至不调用“ set”访问器。 At this point, even if I type in the name of the color and press Enter, it doesn't change. 此时,即使我输入颜色名称并按Enter键,它也不会改变。

If I deselect the object (which sets the property grid's selecteditem to null), then re-select the object, I am then able to change the color by typing in its name. 如果取消选择对象(将属性网格的selecteditem设置为null),然后重新选择该对象,则可以通过键入其名称来更改颜色。 But the popup still does not work. 但是弹出窗口仍然不起作用。

Sometimes it bugs out and the popup won't even open when you click the dropdown arrow. 有时,当您单击下拉箭头时,它会出错,并且甚至无法打开弹出窗口。

EDIT: 编辑:

It's specifically a problem with the popup. 特别是弹出窗口有问题。 If I don't use the popup, I don't get any glitches. 如果不使用弹出窗口,则不会出现任何故障。 Opening the popup basically suspends the change being committed (sending a PropertyChanged event) until the entire control loses focus. 打开弹出窗口基本上会暂停提交的更改(发送PropertyChanged事件),直到整个控件失去焦点。 So once I click on another window or another focusable control, the property grid updates the change. 因此,一旦我单击另一个窗口或另一个可聚焦控件,属性网格就会更新更改。

The question is: why does double clicking or pressing enter cause a change commit, but clicking an item in the popup doesn't? 问题是:为什么双击或按Enter键会导致更改提交,但是单击弹出窗口中的项却没有?

I figured out what is causing the issue. 我弄清楚是什么原因造成的。 I have set the window style WS_EX_COMPOSITED on one of the property grid's parents. 我已经在属性网格的父级之一上设置了窗口样式WS_EX_COMPOSITED。 Disabling this style results in the PropertyGrid functioning normally again. 禁用此样式将导致PropertyGrid再次正常运行。

Unfortunately I need this style to reduce flickering in my application. 不幸的是,我需要这种样式来减少应用程序中的闪烁。 So I will most likely have to use something other than a PropertyGrid to change my object's properties. 因此,我很可能不得不使用除PropertyGrid之外的其他东西来更改对象的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM