Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How can I have access to background screen objects?
PostPosted: Fri May 08, 2015 11:56 am 

Joined: Fri May 08, 2015 11:18 am
Posts: 1

Offline
I've started an application and I created a screen with another screen in background. When the application is running the objects in the background screen are enabled.

I'd like to know how I can control the objects present in background screen by the main screen.

Thanks in advance!


 Profile  
 
 Post subject: Re: How can I have access to background screen objects?
PostPosted: Thu May 28, 2015 9:13 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 102

Offline
I don't know what you know about scripting, but you can use objects in the background screen like you would in the main screen via scripting control. iX developer sets a screen as a "background screen" by using the background screen as the base class for the main screen. As long as no objects are declared as private in the background screen, the main screen will be given access by the rights of inheritance.

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: How can I have access to background screen objects?
PostPosted: Thu Jan 11, 2018 3:25 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 17

Offline
Hi,
I am using the following code placed in a scriptmodule called in a screen to access all his button controls:

public static void MyMethod(object screen)
{
System.Collections.Generic.List<Neo.ApplicationFramework.Controls.Button> buttons = GetLogicalChildCollectionVis<Neo.ApplicationFramework.Controls.Button>(screen);
foreach (Neo.ApplicationFramework.Controls.Button button in buttons)
{
..............
}
}


public static System.Collections.Generic.List<T> GetLogicalChildCollectionVis<T>(object parent) where T : DependencyObject
{
System.Collections.Generic.List<T> logicalCollection = new System.Collections.Generic.List<T>();
GetLogicalChildCollectionVis(parent as DependencyObject, logicalCollection);
return logicalCollection;
}

private static void GetLogicalChildCollectionVis<T>(DependencyObject parent, System.Collections.Generic.List<T> logicalCollection) where T : DependencyObject
{
IEnumerable children = LogicalTreeHelper.GetChildren(parent);
foreach (object child in children)
{
if (child is DependencyObject)
{
DependencyObject depChild = child as DependencyObject;
if (child is T)
{
logicalCollection.Add(child as T);
}
GetLogicalChildCollectionVis(depChild, logicalCollection);
}
}
}

My problem is that this screen have one other screen used as a background, my question is, how can I discriminate if a control belongs to the background screen or not? And how can I get the name of the background screen?

Thanks to any help!


 Profile  
 
 Post subject: Re: How can I have access to background screen objects?
PostPosted: Thu Jan 11, 2018 8:00 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 102

Offline
I'm assuming when you pass "screen" to your function you are passing "this". To extract the background screen so your function knows to ignore it, pass "base". If the object shows up in both this's and base's list you know it's in this's because it's in base's.

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: How can I have access to background screen objects?
PostPosted: Thu Jan 11, 2018 9:29 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 17

Offline
Hi,
thanks for the answer, the problem is that if i pass base instead off this the compiler give this error:
“Use of keyword ‘base’ is not valid in this context”
I can’t understand why.


 Profile  
 
 Post subject: Re: How can I have access to background screen objects?
PostPosted: Fri Jan 12, 2018 10:47 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 102

Offline
You're right. I forgot base is only a keyword and thus can't be passed to functions. Where are you using this code? If it's from within the screen you can just pass "Globals.<background_screen_name>" for the background screen manually. If you want to do this programmatically, you would need to create a function that returns a screen based on the type and use screen.GetType().BaseType to get the type of the background screen.

I've never tried getting screen from type, but maybe this might work. It's a modification of a function I've used to get tag from name
Code:
public static object GetBaseScreen(object screen)
{
   Type type = screen.GetType().BaseType;
   FieldInfo[] props = Globals.GetType().GetFields();
   foreach (FieldInfo prop in props) {
      if (prop.FieldType.Equals(type)) {
         return prop.GetValue(Globals);
      }
   }
   return null;
}

This code uses reflection - "using System.Reflection;".

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: