标签:c style class blog code java
小梦给大家带来windows phone 8.1应用开发实战教程,分享自己学习,开发过程中的经验和技巧。
本例共有三个页面:MainPage,BlankPage1,BlankPage2。
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto"/>
<RowDefinition Height="80"/>
<RowDefinition
Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition
Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="这是主页"
Grid.Row="0" FontSize="40"></TextBlock>
<StackPanel Grid.Row="1"
Orientation="Horizontal">
<TextBlock Text="网站:" FontSize="40"
Margin="0,0,0,30" Width="88"/>
<TextBox x:Name="textName" Height="40"
Margin="0,10,0,0" Width="260" />
</StackPanel>
<StackPanel
Grid.Row="2" Orientation="Horizontal">
<TextBlock Text="网址:"
FontSize="40" Margin="0,0,0,30" Width="88"/>
<TextBox
x:Name="textAdress" Height="40" Margin="0,10,0,0" Width="260"
/>
</StackPanel>
<StackPanel Grid.Row="3"
Orientation="Horizontal">
<TextBlock Text="内容:" FontSize="40"
Margin="0,0,0,30" Width="88"/>
<TextBox x:Name="textContent"
Height="40" Margin="0,10,0,0" Width="260"
/>
</StackPanel>
<Button Content="去第二页" Grid.Row="4"
Margin="122,147.667,0,147" Click="Button_Click"/>
</Grid>
1 <Grid> 2 <Grid.RowDefinitions> 3 <RowDefinition Height="Auto"/> 4 <RowDefinition Height="80"/> 5 <RowDefinition Height="*"/> 6 </Grid.RowDefinitions> 7 <TextBlock Text="这是第三页" Grid.Row="0" FontSize="40"></TextBlock> 8 <TextBox Name="text" Grid.Row="1" Height="60" Margin="0,9.667,10,0"/> 9 <Button Content="我要直接回主页" Grid.Row="2" Margin="122,147.667,0,147" Click="Button_Click"/> 10 </Grid>
1 private void Button_Click(object sender, RoutedEventArgs e) 2 3 { 4 Website web=new Website() 5 { 6 Name=this.textName.Text, 7 Address=this.textAdress.Text, 8 Content=this.textContent.Text 9 }; 10 Frame.Navigate(typeof(BlankPage1),web); //对应知识点3,即传递多个参数时建立一个对象,传递对象即可。 11 }
1 protected override void OnNavigatedTo(NavigationEventArgs e)//重写OnNavigatedTo接受从maingape页面传递来的参数。 2 { 3 var web = (Website)e.Parameter; 4 this.textName.Text = web.Name; 5 this.textAdress.Text = web.Address; 6 this.textContent.Text = web.Content; 7 HardwareButtons.BackPressed += HardwareButtons_BackPressed;//注册重写后退按钮事件 8 } 9 10 private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)//重写后退按钮,如果要对所有页面使用,可以放在App.Xaml.cs的APP初始化函数中重写。 11 { 12 e.Handled = true; 13 14 if (Frame.CanGoBack) 15 Frame.GoBack(); 16 } 17 18 private void Button_Click(object sender, RoutedEventArgs e)//传递单个参数 19 20 { 21 Frame.Navigate(typeof(BlankPage2), "我是从第二页传送过来的!!"); 22 }
1 protected override void OnNavigatedTo(NavigationEventArgs e) 2 { 3 text.Text = (string)e.Parameter; 4 Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);//对应知识点5,清楚后退堆栈的最后一条历史,本例中即第二页,删除后即可从第三页直接到主页。 5 } 6 7 private void Button_Click(object sender, RoutedEventArgs e) 8 { 9 Frame.GoBack(); 10 }
PS:希望热爱windows phone开发的大神,小白能来编程小梦一起多多交流,windows Phone开发者本身就比较少,小梦希望大家有一个交流的平台,欢迎大家光临!
windows phone8.1:页面导航详解,布布扣,bubuko.com
标签:c style class blog code java
原文地址:http://www.cnblogs.com/bcmeng/p/3776624.html