zoukankan      html  css  js  c++  java
  • SL学习笔记 Navigation Framework

       推荐看Tim Heuer的视频:http://silverlight.net/learn/videos/silverlight-videos/navigation-framework/

       新建SL应用程序后,首先引入System.Windows.Controls和System.Windows.Controls.Navigation。

    在App中引用命名空间:

      xmlns:navcore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"

    添加映射规则:

    <navcore:UriMapper x:Key="uriMapper" >
                <navcore:UriMapping Uri="Home" MappedUri="/Views/HomePage.xaml" />
                      </navcore:UriMapper>

    然后在MainPage中引用命名空间:

     xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

    添加导航按钮:

     <HyperlinkButton  Tag="Home"  Click="NavigateButton_Click"  Content="Home" FontSize="24" />

    并创建事件:

     private void NavigateButton_Click(object sender, RoutedEventArgs e)
            {
                HyperlinkButton btn = sender as HyperlinkButton;
                string url = btn.Tag.ToString();

                this.MainFrame.Navigate(new Uri(url, UriKind.Relative));
            }

    添加导航框架:

     <navigation:Frame x:Name="MainFrame" UriMapper="{StaticResource uriMapper}"  HorizontalAlignment="Stretch" Margin="20" Source="Home"  />

    PS:Tim Heuer那里下载的代码不能运行,必须添加 UriMapper="{StaticResource uriMapper}" .这个问题困扰了我好久,还好视频里面的评论有人提到,我才解决。

    在SL项目中添加文件夹View,然后添加HomePage.xaml。

    作  者:doku
    出  处:http://www.cnblogs.com/kulong995/
    关于作者:喜欢编程,喜欢美食,专注于.NET项目开发。
    版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
    声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!

  • 相关阅读:
    246.Strobogrammatic Number
    245.Shortest Word Distance III
    244.Shortest Word Distance II
    243.Shortest Word Distance
    242. Valid Anagram
    241. Different Ways to Add Parentheses
    240.Search in a 2D Matrix II
    239. Sliding Window Maximum
    238. Product of Array Except Self
    postgres 行列转换
  • 原文地址:https://www.cnblogs.com/kulong995/p/1687210.html
Copyright © 2011-2022 走看看