Windows Phone – Passing arguments between pages and Input Scope

On my serie of posts for developing on Windows Phone, today I would like to illustrate how I can pass arguments to page when navigating to it and apply input scope to reduce the input panel for specific input data format. Let’s start with passing argument to page before opening it. If you are Windows Form/WPF developer, you may use a property to get data for form before opening or loading it. This data will be provided to some pre-processing tasks before showing form to user. For example

Form1 f1 = new Form1();
f1.DataToBeSet = "Hihihaha";

However in Silverlight or Windows Phone, there is no Show() or ShowDialog() function anymore. I can only navigate between page like following.

NavigationService.Navigate(new Uri("/WebPage.xaml", UriKind.Relative));

So then how can I pass argument for page before showing it to users. It is pretty simple, you just need to add some query arguments in Uri and get them back when the new page is loading as following

//On calling Page
NavigationService.Navigate(new Uri("/BrowsePage.xaml?RSSSource="+strSource, UriKind.Relative));
//On the BrowsePage side
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
			string strRSSSource = "";
			NavigationContext.QueryString.TryGetValue("RSSSource", out strRSSSource);
	catch (Exception ex)

So you can see how I can pass argument RSSSource to BrowserPage.xaml.

The next section in this post I would like to discuss about InputScope and input panel. In windows phone the Software Input Panel can not be customized anymore. Although you can not customize the input panel but you can adjust its view according to input context. For example if you mark a TextBox as requiring a TelephoneNumber you will get a numerical keypad . There are a number of different contexts supported which you can read here . Some of typical InputScopeNameValue are listed below
– Password
– TelephoneNumber
– EmailNameOrAddress
– Maps
– NameOrPhoneNumber
– Url

To apply the input context for the text box, you just need to set the InputScope property to one of listed valued in link above to get a matched panel.

<TextBox InputScope="Url" Text="" x:Name="txtURL" Margin="0,50,0,0" Height="71" VerticalAlignment="Top">

The differences of input panel between with and without setting InputScope you can see in example below.

With InputScope Without InputScope

Update 07.04.2010: Remove some quotations cause of copyright.


Leave a comment

Your email address will not be published. Required fields are marked *