Skip to content
wxWidgets - Cross-Platform GUI Library
Stop Russia agression of Ukraine
Stop the War in Ukraine

wxWidgets is united with the people of Ukraine and the international community.

More Resourceful Property Grid

Posted on

Just a quick note to say that it is now possible to define wxPropertyGrid controls in XRC, e.g. here is a minimal example:

<object class="wxPropertyGrid" name="grid_music">
    <property class="wxStringProperty">
        <label>Name</label>
        <value>Now And Then</value>
    </property>
    <property class="wxIntProperty">
        <label>Year</label>
        <value>2023</value>
    </property>
</object>

Support for wxPropertyGrid must be explicitly enabled by registering the XRC handler for it, so the code loading the XRC file including the fragment above would look like this:

// Include declaration of the XRC handler for wxPropertyGrid.
#include "wx/xrc/xh_propgrid.h"

bool MyApp::OnInit() {
    auto xrc = wxXmlResource::Get();

    // Initialize all standard handlers.
    xrc->InitAllHandlers();

    // And add this one which is not standard.
    xrc->AddHandler(new wxPropertyGridXmlHandler);

    if ( !xrc->Load("propgrid.xrc") )
    {
        wxLogError("XRC file couldn't be loaded.");
        return false;
    }

    ...
}

The updated sample contains a more complex example of wxPropertyGridManager defined in XRC and the documentation has been updated to describe the supported elements.

Comments

Blog Archive