Getting Started
By default, Tray Notification is disabled in the application. To turn it on, open the Model Editor and set the value of the TrayIconEnable property to true (as shown in the image below).
Each action available in the context menu of the application's tray icon is an instance of the SimpleAction class and can be accessed via the Application Model (see the figure below).
It is also possible to customize actions for the File context menu through the CustomClose node.
There is an opportunity to adjust the behavior of Tray Notification in the source code. The XafariTrayNotifyIconController class is a WindowController descendant that has several unique members that can be utilized by the developer:
- The NavigationMenuVisible public field,
- The CustomInitializeItems public event,
- The CustomExecuteItem event,
- The UpdateNavigationItems public method.
The code sample below explains it in details:
- c#
- VB
private void testmethod()
{
XafariTrayNotifyIconController tray = Frame.GetController<XafariTrayNotifyIconController>();
tray.NavigationMenuVisible = false;
tray.CustomInitializeItems += tray_CustomInitializeItems;
tray.CustomExecuteItem += tray_CustomExecuteItem;
tray.UpdateNavigationItems();
}
void tray_CustomExecuteItem(object sender, CustomExecuteItemEventArgs e)
{//Implementing the trigger for e.CurrentItem
}
private void tray_CustomInitializeItems(object sender, CustomInitializeItemsEventArgs e)
{//Adding items to the e.Items collection
}
Private Sub testmethod()
Dim tray As XafariTrayNotifyIconController = Frame.GetController(Of XafariTrayNotifyIconController)()
tray.NavigationMenuVisible = False
tray.CustomInitializeItems += tray_CustomInitializeItems
tray.CustomExecuteItem += tray_CustomExecuteItem
tray.UpdateNavigationItems()
End Sub
Private Sub tray_CustomExecuteItem(ByVal sender As Object, ByVal e As CustomExecuteItemEventArgs)
'Implementing the trigger for e.CurrentItem
End Sub
Private Sub tray_CustomInitializeItems(ByVal sender As Object, ByVal e As CustomInitializeItemsEventArgs)
'Adding items to the e.Items collection
End Sub
The NavigationMenuVisible bool type field sets the navigation menu available in the tray icon context menu.
The CustomInitializeItems event is used to add custom items to the navigation menu; the CustomExecuteItem event provides the logic for calling custom methods when the end user clicks the context menu items.
Important: CustomInitializeItems and CustomExecuteItem should be always used together in order to provide stable functioning of the custom nodes. The default method of calling the nodes cannot guarantee the satisfying level of stability in case of using custom nodes.
To replace the default implementation with a custom one, set the Handled flag to true (as demonstrated below).
- c#
- VB
private void tray_CustomExecuteItem(object sender, CustomExecuteItemEventArgs e)
{
ForExampleExecute(e.CurrentItem);
}
Private Sub tray_CustomExecuteItem(ByVal sender As Object, ByVal e As CustomExecuteItemEventArgs)
ForExampleExecute(e.CurrentItem)
End Sub
The code below shows the usage of the CustomExecuteItem event:
- c#
- VB
private void tray_CustomInitializeItems(object sender, CustomInitializeItemsEventArgs e)
{
e.Handled = true;
e.Items.Add(new ChoiceActionItem());
}
Private Sub tray_CustomInitializeItems(ByVal sender As Object, ByVal e As CustomInitializeItemsEventArgs)
e.Handled = True
e.Items.Add(New ChoiceActionItem())
End Sub
The UpdateNavigationItems method updates the tray context menu. It is a virtual method that can be used either to display the changes emerged in the runtime or to customize the structure and behavior of the tray context menu in any possible way.