Silverlight之Frame传递多个参数并获取完整参数

          

    if (strXapOrXaml == "xaml")
                {
                    string[] s = { "ClientBin" };
                    //这里控制是相对地址还是绝对地址
                    string url = "";
                    if (menuUrl.StartsWith("http://"))
                    {
                        url = menuUrl.ToString().Trim();
                    }
                    else
                    {
                        url = App.Current.Host.Source.OriginalString.ToString().Split(s, StringSplitOptions.RemoveEmptyEntries)[0] + menuUrl.ToString().Trim(new char[] { '.', '/' });
                    }
                    cpt.frmMain.Navigate(new Uri("/AspxContainer.xaml?tourl=" + url, UriKind.Relative)); 
                    tchA.imgRefresh.Tag = url; //获取页面URL地址并赋值 2013-01-30
                }


 

这里比如url中带多个参数:

./YSQ/page2.aspx?stype=2&sdefault=0

 

<navigation:Page x:Class="WebMain.AspxContainer" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:divtools="clr-namespace:Divelements.SilverlightTools;assembly=Divelements.SilverlightTools"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="AspxContainer Page">
    <Grid x:Name="LayoutRoot">
        <divtools:HtmlHost x:Name="htmlPlaceholderHost1"  SourceUri="http://www.baidu.com" Margin="0,0,0,0"/>
    </Grid>
</navigation:Page>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace WebMain
{
    public partial class AspxContainer : Page
    {
        public AspxContainer()
        {
            InitializeComponent();
        }

        // 当用户导航到此页面时执行。
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            if (this.NavigationContext.QueryString.ContainsKey("tourl"))
            { 
                //加载页面
                string url = e.Uri.ToString().Substring(26); //去掉前面的字符串/AspxContainer.xaml?tourl=
                this.htmlPlaceholderHost1.SourceUri = new Uri(url, UriKind.RelativeOrAbsolute);
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
        }

    }
}


 

 

在重构函数OnNavigatedTo函数中使用参数e的Uri属性,是解决这个问题的关键!

你可能感兴趣的:(Silverlight之Frame传递多个参数并获取完整参数)