In this post, we will look at creating a new UII application from scratch, that will be used in USD. The UII application will be a Windows Forms application, where we can add fields, add any business logic, and ultimately update the $Context in USD as well as be notified when another application updates the $Context.
In Visual Studio, go to File->Next Project and select UII Windows Forms Hosted Control:
This creates the project below:
Go to Manage NuGet Packages:
Update the latest packages:
So the assemblies are now found:
Right click the cs file and open in Designer:
You will see:
We will add a text box for First Name, and a button that we will use to update the context in USD:
In the Microsoft.Uii.Csr namespace, we have various methods, including:
- NotifyContextChange, that notifies this control that the context has changed
- FireContextChange, updates the replacement parameter in USD with a new context value.
The code behind Update Context will call FireContextChange to alert USD that the context has changed. NotifyContextChange is also called to invoke the method in the custom control, so we can perform any actions when this changes:
Now, compile the project and copy the assembly to the USD client directory:
Next, register the control in USD. Go to Settings->USD:
Select Hosted Controls:
Select New:
Now create a new hosted control:
- Name = Test UII Hosted Control
- USD Type = CCA Hosted Application
- Application Type = Hosted Control
- Global, MainPanel
- Carl.UIIHostedControl, Carl.UIIHostedControl.UiiWinformControl
Now, run the USD client. We will open the new UII control through the debugger:
Go to the new control and enter some text:
Click Update Context. You will see the context has a new parameter that did not exist before, called firstname:
Now what if a different hosted control updates the context, and we want our control to be updated as well? Using NotifyContextChange, our control can be updated:
On loading the control (I am loading this on SessionNew), it is populated with the firstname of the $context, which comes from the firstname field of the incident:
Now, if we update the firstname field on the Incident hosted control, it will update the $context.firstname, which will fire the NotifyContextChange in our custom hosted control, and update the field:
Test UII Hosted Control updated:
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL