Silverlight之Frame傳遞多個引數並獲取完整引數

暖楓無敵發表於2013-08-09

          

    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屬性,是解決這個問題的關鍵!

相關文章