723 views
in GUI Development by

This is the structure of my class. 

MyGroup is parent for all and based on condition I am loading or changing the view.

My question is I am in class HomeMenuVertical in that screen i am having button called Enter, on click I am checking some condition and based on that I want to load class EquipmentDataTemplate.

I tried to use SwitchToDialog Methond but it was not working the way I want..

What should I do in such case.

Kindly Help!!

1 Answer

0 votes
by

Hello,

what do you mean with load class EquipmentDataTemplate

- Do you want corresponding component to appear additionally on the screen?

- Do you want to replace the actual HomeMenuVertical component by EquipmentDataTemplate?

Usually the Dialogs functionality is ideal to manage the navigation and transition between screens (dialogs). In such case, however, all affected components have to be presented by using the Dialogs functionality. Anyway, you are not obligated to use this functionality.

If you prefer, you can also create and display of the desired components programmatically. For example:

// Create anew instance of the desired component
var Example::EquipmentDataTemplate component = new Example::EquipmentDataTemplate;

// Add it directly to the application component
GetRoot().Add( component, 0 );

// .... or add it to the actual 'this' component
Add( component, 0 );

Please see also the section Compose the component programmatically.

Best regards

Paul Banach

by
Yes, I want to replace the actual HomeMenuVertical component by EquipmentDataTemplate.

When I try the above code it give me error as "View is already in group";
by
Hello,

In such case the best approach would be to use the Dialogs functionality. Do following:

- Use PresentDialog() with HomeMenuVertical to present this component as dialog.

- When you want to switch to other component use SwitchToDialog().

This will hide the previously presented component and display the new one. If HomeMenuVertical has not been presented by using PresentDialog(), SwitchToDialog() will limit to display the new component without hiding the old one. Maybe this is the problem you have ...?

Best regards

Paul Banach
by
Regarding the above code, you should use only one of the both Add() operations. Please note the // ... or ... comment.
by
I am trying to do something like this. Removing the current Template and adding new one. But its not working.

var Application::HomeMenuVertical menuComp = new Application::HomeMenuVertical;
var Application::EquipmentDataTemplate component = new Application::EquipmentDataTemplate;
// Add it directly to the application component
GetRoot().Remove( menuComp);
GetRoot().Add( component, 0 );
by

In your code, you create a new instance of HomeMenuVertical and then you try to remove it. Since this component is newly created and not yet part of the view tree, the operation will fail and you will get an error.

If you want to remove a GUI component, you have to know its concrete (already existing) instance. Assuming, you perform the code in context of HomeMenuVertical, then 'this' represents this instance:

var Application::EquipmentDataTemplate component = new Application::EquipmentDataTemplate;
var Core::Root                         root      = GetRoot();

// Add it directly to the application component
root.Remove( this );
root.Add( component, 0 );

Anyway, I would suggest to use the Dialogs functionality.

Best regards

Paul Banach

by
getting the same error view is not in this group. on below line.

root.Remove(this);
by

The above example assumed, all components are nested directly within the root object. Evidently, this is not the case in your project. In such case try following:

var Application::EquipmentDataTemplate component = new Application::EquipmentDataTemplate;
var Core::Root                         root      = GetRoot();

// Add it directly to the application component
Owner.Remove( this );
root.Add( component, 0 );

In the above code note the usage of 'Owner' which refers the GUI component containing 'this' component. This should avoid the error message. More advanced solution avoids race conditions:

// If 'this' component is already removed
if ( Owner == null )
  return;

var Application::EquipmentDataTemplate component = new Application::EquipmentDataTemplate;
var Core::Root                         root      = GetRoot();

// Add it directly to the application component
Owner.Remove( this );
root.Add( component, 0 );

Without knowing your project it is difficult to understand the relations between the components. Have you read the artucle Understand the view tree and the Owner relationships?

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...