Property Manager Page driven by data model
Property Manager Page driven by data model

Data model

Start by defining the data model required to be filled by property manager page.

public class DataModelSimple
{
    public string Text { get; set; }
    public int Size { get; set; } = 48;
    public double Number { get; set; } = 10.5;
}

Use properties with public getters and setters

Events handler

Create handler for property manager page by inheriting the public class from PropertyManagerPageHandlerEx class.

This class will be instantiated by the framework and will allow handling the property manager specific events from the add-in.

[ComVisible(true)]
public class MyPMPageHandler : PropertyManagerPageHandlerEx
{
}

Class must be com visible and have public parameterless constructor.

Ignoring members

If it is required to exclude the members in the data model from control generation such members should be decorated with IgnoreBindingAttribute

public class DataModelIgnore
{
    public string Text { get; set; }

    [IgnoreBinding]
    public int CalculatedField { get; set; } //control will not be generated for this field
}

Creating instance

Create instance of the property manager page by passing the type of the handler and data model instance into the generic arguments

Data model can contain predefined (default) values. Framework will automatically use this values in the corresponding controls.

private PropertyManagerPageEx<MyPMPageHandler, DataModel> m_Page;
private DataModel m_Data = new DataModel();

private enum Commands_e
{
    ShowPmpPage
}

public override bool OnConnect()
{
    m_Page = new PropertyManagerPageEx<MyPMPageHandler, DataModel>(App);
    AddCommandGroup<Commands_e>(ShowPmpPage);
    return true;
}

private void ShowPmpPage(Commands_e cmd)
{
    m_Page.Handler.Closed += OnPageClosed;
    m_Page.Show(m_Data);
}

private void OnPageClosed(swPropertyManagerPageCloseReasons_e reason)
{
    Debug.Print($"Text: {m_Data.Simple.Text}");
    Debug.Print($"Size: {m_Data.Simple.Size}");
    Debug.Print($"Number: {m_Data.Simple.Number}");
}

Store instance of the data model and the property page in the class variables. This will allow to reuse the data model in the different page instances.