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

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

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

1NavigationService.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
02NavigationService.Navigate(new Uri("/BrowsePage.xaml?RSSSource="+strSource, UriKind.Relative));
03...
04//On the BrowsePage side
05private 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.

转载于:https://www.cnblogs.com/nio-nio/archive/2010/09/18/1830497.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值