Windows Phone – Passing arguments between pages and Input Scope

http://rongchaua.net/blog/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

1 Form1 f1 = new Form1();
2 f1.DataToBeSet = "Hihihaha";
3 f1.Show();

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

1 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

01 //On calling Page
02 NavigationService.Navigate(new Uri("/BrowsePage.xaml?RSSSource="+strSource, UriKind.Relative));
03 ...
04 //On the BrowsePage side
05 private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
06 {
07     try
08     {
09         ...
10             string strRSSSource = "";
11             NavigationContext.QueryString.TryGetValue("RSSSource", out strRSSSource);
12             vmDatabase.GetRssItems(strRSSSource);
13         ...
14     }
15     catch (Exception ex)
16     {
17         MessageBox.Show(ex.Message);
18     }
19 }

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

InputScope
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 http://msdn.microsoft.com/en-us/library/system.windows.input.inputscopenamevalue%28VS.96%29.aspx . 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.

1 <TextBox InputScope="Url" Text="http://vnexpress.net/RSS/GL/trang-chu.rss" 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.

posted @ 2010-09-18 23:54  大厨无盐煮  阅读(303)  评论(0编辑  收藏  举报