Set initial values when compound widget is opened

Hello everyone,

the structure to which this question refers is as follows:

I am trying to set initial values inside of a compund widget (e.g. content displayed on content control-widget, values of local properties). This should happen every time the dialog (and thus the compund widget) is opened.

I already tried…:

  • …to use the “OnWidgetsReady”-event. Unfortunately, this only works the first time opening it.
  • … setting the initial values as soon as the dialog gets closed. Unfortunately, this does not work because the closing event is processed before the internal eventbindings (which should set the initial values)

Do any of you have an idea how I can achieve the requirements?
Many thanks in advance.

1 Like

Hi Jonas @c564347

I have a few ideas, and hopefully others have additional ones they can add.

My first idea sounds a little old-fashioned, but you could write program code that handles resetting your widget values. This does mean you need to bind information to OpcUa variables, but it’s straightforward as your code can tell when the dialog is opened/shut and adjust the bound variables accordingly. I often find this the easiest option because code is more flexible than eventbindings.

A second idea I have is to use session variables. You could keep track of whether a dialog is open or not by changing the value of a session variable. When that variable’s value changes, you know that the dialog has opened or closed. You can then use that information to trigger events. I’ve also seen projects where someone makes a “DialogHasJustOpened” variable which is set True when the dialog opens, and then False after all of the initial information has been loaded.

You could also trigger actions to occur when the dialog opens using the DialogOpened event rather than after it closes. There will probably be a slight delay between the dialog opening and everything resetting, but that depends on how busy your dialog content is.

1 Like

Hi Marcus,
First of all, thank you for the quick and detailed answer.

However, I want to implement the function completely inside of the compound widget (cpw) and therefore do not want to use any additional variables that have to be linked to it.

I managed to achieved the desired function with the following workaround:

The initial settings are set everytime the dialog closes:

  • Invisible image (Image widget without referenced picture) widget inserted in cpw
  • As soon as the “close” button inside the cpw is clicked, a internal sequence is resetting all values, contents and properties. The last step of this sequence toggles the “visible” property of the image
  • This can be detected by the “VisibleChanged” event of the image and trigger the “CloseDialog” event of the cpw.

    This event activates a clientsystem action and thus closes the Dialog with the cpw.

I am aware that this is not very elegant, but it means that everything is encapsulated in the cpw.

Thanks again and best regards!

1 Like

I’m glad you found a solution. I didn’t realize that you wanted to keep everything within the compound widget itself, but that does make a clean implementation for anyone who uses that widget later on.

Thanks for sharing!

1 Like