This example shows how to pass parameters to a UXWindow during startup.
Example
Description
In certain cases, you may want to open a window with certain settings applied, such as the window width, window height, title, and icon. Often times, you may also want to pass custom data as parameter to the window being opened. You can use WindowOptions to achieve many of these tasks. The WindowOptions is a DependencyObject, which means you can instantiate this class in the XAML and bind it to the CommandParameter of a command source.
WindowOptions class provides numerous properties that you can set to preconfigure a window when used with LaunchApplication command, which is described in the folllowng list.
- Uri
Specifies the target URI of the window to be opened, which is required for the LaunchApplication command to work properly.
- ForceSingleInstance
When set to true, the window will be opened only if there are no existing windows with identical window identifier. For instance, if there is a window that associated to Notepad.xaml in the desktop, the command will no longer open the window that target Notepad.xaml.
- NavigationBarVisibility
By default, opening a new UXNavigationWindow will show the navigation bar element. You can hide the navigation bar in certain cases without have to change the settings in the existing navigation window by specifying the NavigationBarVisibility property of the window options to Collapse.
- ReactivateExistingInstance
This property works in conjunction with the ForceSingleInstance property. When set to true, the existing window that matches the identity of the target window will be activated if it is currently in inactive state, or restored if it is currently in minimize state.
- StartupParameters
Specifies the custom data to be passed as startup parameters for the target window. The data that passed in this property can be obtained from the StartupParameters property of the window during the Loaded event of the window. Alternatively, you can also access the custom data during the Launched event, which is a bubbling routed event raised by the UXDesktop upon successful window launch.
- UID
Specifies the unique identifier for the target window. In most cases, you do not need to specify this property manually as the windowing framework can assign the unique identifier automatically.
- WindowName
Specifies the name of the target window, which overrides the WindowName property of the window.
- WindowGroupName
Specifies the group name of the target window, which overrides the GroupName property of the window.
- WindowWidth
Specifies the width of the target window, which overrides the Width property of the window.
- WindowHeight
Specifies the width of the target window, which overrides the Height property of the window.
- WindowTitle
Specifies the title of the target window, which overrides the Header property of the window.
- WindowIcon
Specifies the icon of the target window, which overrides the Icon property of the window.
The following example shows how to open a window and pass a custom data to the startup parameter, then obtain the passed data in the target window in Loaded event.
Code
XAML | ![]() |
---|---|
<Intersoft:UXWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Intersoft="http://intersoft.clientui.com/schemas"> <Grid x:Name="LayoutRoot"> <StackPanel> <Intersoft:UXButton Content="Button" HorizontalAlignment="Left" Command="Intersoft:WindowCommands.LaunchApplication"> <Intersoft:UXButton.CommandParameter> <Intersoft:WindowOptions Uri="/Desktop/HomeWindow.xaml" StartupParameters="Hello ClientUI"/> </Intersoft:UXButton.CommandParameter> </StackPanel> </Grid> </Intersoft:UXWindow> |
C# | ![]() |
---|---|
public partial class HomeWindow : UXWindow { public HomeWindow() { InitializeComponent(); this.Loaded += new RoutedEventHandler(HomeWindow_Loaded); } private void HomeWindow_Loaded(object sender, RoutedEventArgs e) { object data = this.StartupParameters; if (data is string) MessageBox.Show(data.ToString()); } } |