zoukankan      html  css  js  c++  java
  • Passing data to Navigation Pages

    1. Begin by opening the project NavAppFromScratch you were working on in the previous section.

    2. Open the xaml for View1.xmal and modify the source to include a ComboBox under the Button:

     <Combobox Padding="10"  Margin="10" x:Name="Color" Width="100">

      <ComboBoxItem Content="Blue" IsSelected="True" />

      <ComboBoxItem Content="Red" />

      <ComboBoxItem Content="Green" />

     </ComboBox>

    3. Next open the code behind for View1.xaml and edit the Button_Click event handler to pass the selected color in the querystring of the Uri passed to the Navigate method:

    private void Button_Click(object sender, RoutedEventArgs e)

    {

      string color=this.Color.SelectionBoxItem.ToString();

      NavigateionService.Navigate(new Uri(string.Format("/InnverView1.xmal?Color={0}",color),UriKind.Relative));

    }

    4. Open the InnverView1.xaml file and add a second TextBlock below the existing TextBlock using a stackPanel:

    <Grid x:Name="LayoutRoot">

      <StackPanel Orientation="Vertical">

        <TextBlock Text="Inner View 1" x:Name="ViewHeader" FontSize="40" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" />

        <TextBlock Text="(Blue)" x:Name="ViewColor" FontSize="30" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" />

      </StackPanel>

    </Grid>

    5. Open the code behind for InnerView1.xaml and retrieve the passed color using the Navigationcontext object. Then add a switch statement to change the color of the TextBlocks and edit the Text for the second TextBlock:

    protected override void OnNavigatedTo(NavigationEventArgs e)

    {

      string color=NavigationContext.Querystring["Color"].ToString();  

      Brush b;

      switch(color)

      {

        case "Red":

          b = new SolidColorBrush(Color.FromArgb(255,255,0,0));

          ViewHeader.Foreground=b;

          ViewColor.Foreground=b;

          ViewColor.Text="(Red)";

          break;

        case "Green":

          b = new SolidColorBrush(Color.FromArgb(255,0,255,0));

          ViewHeader.Foreground=b;

          ViewColor.Foreground=b;

          ViewColor.Text="(Green)";

          break;

        default:

          b = new SolidColorBrush(Color.FromArgb(255,0,0,255));

          ViewHeader.Foreground=b;

          ViewColor.Foreground=b;

          ViewColor.Text="(Blue)";

          break;

    }

    }

  • 相关阅读:
    新手小白如何购买阿里云服务器?
    nginx 泛域名解析 实现 多域名动态网站内容
    CentOS 安装MySQL 详细教程
    CentOS添加并挂载新硬盘
    docker下nginx+tomcat 文件的上传与访问
    关于人人开源renren-fast-vue 中npm install各种报错的解决方案
    《素面朝天,青春盛宴》
    手把手教你springboot中导出数据到excel中
    使Word文档和PDF文件不可被复制的方法
    博客园中使用MarkDown编辑器向博文中添加视频
  • 原文地址:https://www.cnblogs.com/jerrychenfly/p/2140522.html
Copyright © 2011-2022 走看看