Access MainWindowcontrols in other files

Jan 17, 2011 at 4:20 PM


The problem description is as follows:

Normally when new session is created CCA update the label expander header in desktop service in AfterSessionShowEvent.

Desktop.lblExpanderHeader.Content = CustomerRc.sessionName;

In my scenario I need to update the header with Customer Name, when I get response from an async web service call(After session creation)

 Is there any way in which I can access lblExpanderHeader(Main Window controls) or Desktop service from other hosted application e.g. current session viewer, customer search.

 Timely help on this is highly appreciated.

Jan 26, 2011 at 2:09 AM
Edited Jan 26, 2011 at 12:58 PM

Easy to do ..
I assume you’re doing your query from a HostedControl, and you want to set something on the desktop.. use the UserDefinedCommand on the IDesktopUserActionsConsumer interface.

If you use the UII Solution Starters ( Linked on the downloads area.. ) the Interface is already there, if not, you can add it to your control by adding IDesktopUserActionsConsumer to the class inheritance, then implementing the interface.

For the class ... =

public partial class ShowContextData : HostedWpfControl, IDesktopUserActionsConsumer  

and then the implementation...

#region IDesktopUserActionsConsumer Members

/// <summary>
/// Raised when the desktop loading is complete
/// </summary>
/// <remarks>
/// this is only called on Global Hosted Controls
/// </remarks>
public void DesktopLoadingComplete()
{ }

/// <summary>
/// Provides access to system level Uii Functions
/// </summary>
/// <param name="desktopAccess"></param>
public void SetDesktopUserActionsAccess(IDesktopUserActions desktopAccess)
    if (uiiDesktop == null)
        uiiDesktop = desktopAccess;


Add a globally scoped variable in your class for IDesktopUserActionsConsumer, in my example I called it uiiDesktop,

Now call the userdefinedcommand on the uiiDesktop variable...  such as :

uiiDesktop.UserDefinedCommand("UpdateExpanderLabel", "newName"); 

Next,  add a bit of code to the UserDefinedCommand override in the DesktopService.cs class in the Desktop Project.. Like this:

public override string UserDefinedCommand(string command, string request)
    if (!string.IsNullOrEmpty(command)) 
        if (command.Equals("UpdateExpanderLabel", System.StringComparison.CurrentCultureIgnoreCase))
            if (!string.IsNullOrEmpty(request))
                Desktop.lblExpanderHeader.Content = new System.Windows.Controls.TextBlock() { Text = request }; 

    return base.UserDefinedCommand(command, request);

That help?

Jan 26, 2011 at 12:27 PM

Thanks alot Mat for your reply.

That's pretty cool,we are looking for this option only.

We were aware of UserDefinedCommand but not sure how to implement it.

We will implement this and will let you know in case of any concerns.



Neeraj Sapra