Intersoft ClientUI 8 > ClientUI Fundamentals > Window and Dialog Boxes Overview > Window and Dialog Boxes How-to Topics > How-to: Pass parameters to a UXWindow during Startup |
This example shows how to pass parameters to a UXWindow during startup.
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.
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.
XAML |
Copy Code
|
---|---|
<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# |
Copy Code
|
---|---|
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()); } } |