<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ![](https://box.kancloud.cn/2016-03-18_56eb67c868925.jpg) 上一篇學習了[Silverlight Navigation導航框架URI映射機制](http://www.cnblogs.com/jv9/archive/2011/08/09/2131663.html),其中討論到Silverlight Navigation導航框架傳遞參數的問題。說起導航框架頁面間傳遞參數,是最常用開發技巧之一。本篇將詳細講解Silverlight Navigation導航傳參方法。 傳統Web應用中,由于普通Web頁面屬于無狀態類型頁面,所以各頁面間傳遞參數經常使用Cookies,Session或者ViewState技術傳遞數據。另外,也會經常使用QueryString參數的方式,附加要傳遞的參數到當前URI鏈接,共享參數在服務器端和客戶端之間。相比而言,Silverlight作為富客戶端技術,其應用頁面屬于有狀態類型頁面,簡單的理解,在Silverlight客戶端定義的變量其內容都會被保存在客戶端內存中,當前頁面狀態也將被保存。換句話說,Silverlight頁面間傳遞參數可以定義全局應用級變量進行參數傳遞,但是這種方式會增加應用內存開支,降低應用運行效率,所以不推薦使用。而Silverlight應用另外一種傳遞參數的方法與傳統Web應用傳遞參數方法類似,使用 “QueryString參數”的方式實現頁面間參數傳遞。 **“QueryString參數”方式傳遞參數基礎格式** “QueryString參數”方式傳遞參數,在傳統Web應用傳參中經常用到,Silverlight仍舊使用傳統格式進行URI參數傳遞操作,其格式如下: /Views/Page.xaml?Parameter=Value 以上鏈接中,Page.xaml是一個Silverlight客戶端應用頁面,而需要傳遞的參數名稱為“Parameter”,其參數值為“Value”。通過使用"?"連接頁面名稱和附帶參數,目的頁面通過指定API可以獲取到附帶的參數名稱和參數值。 頁面間,多參數傳遞格式如下: /Views/Page.xaml?Parameter1=Value1&Parameter2=Value2 以上鏈接中使用"&"符號實現在URI中附加多參數,以達到多參數傳遞目的。 由上面可以看出,“QueryString參數”方式傳遞參數主要是通過URI,傳遞方法則與Silverlight導航框架URI地址映射有著密切的聯系。 **“QueryString參數”方式傳遞參數方法** 在上一篇[URI映射機制](http://www.cnblogs.com/jv9/archive/2011/08/09/2131663.html)中,我們曾經介紹過通過在App.xaml資源文件中設置MapperUri,從Home頁面傳遞單一參數到About頁面,其映射規則是: <uriMapper:UriMapping Uri="/About/{parameter}" MappedUri="/Views/About.xaml?parameter={parameter}"/> 在源頁面,通過NavigationService.Navigate方法對頁面進行導航切換,其中附帶需要傳遞的參數, ~~~ privatevoid btSend_Click(object sender, RoutedEventArgs e) { this.NavigationService.Navigate(new Uri(String.Format("/About/"+ txtQueryString.Text.Trim()), UriKind.Relative)); } ~~~ 在Navigation導航框架運行時,在瀏覽器中URI地址格式為: http://localhost:49750/SilverlightNavigationDemoTestPage.aspx#/About/SilverlightChina 通過URI地址映射解析,其實際地址將指向到"/Views/About.xaml?parameter=SilverlightChina", ![](https://box.kancloud.cn/2016-03-18_56eb67d09fb39.gif) 根據以上介紹,如果需要傳遞多參數到目的頁面,則需要添加新的地址映射規則,其中附帶多個參數即可。例如添加規則: <uriMapper:UriMappingUri="/About/{name}&amp;{url}" MappedUri="/Views/About.xaml?name={name}&amp;url={url}"/> 使用NavigationService.Navigate方法對頁面進行導航切換,其中附帶需要傳遞的多個參數: ~~~ privatevoid btSendMultiple_Click(object sender, RoutedEventArgs e) { this.NavigationService.Navigate(new Uri(String.Format("/About/"+ txtNameString.Text.Trim()+"&"+ txtURLString.Text.Trim()), UriKind.Relative)); } ~~~ 在映射規則中,使用{name}和{url} 作為URI通用符,兩者使用"&amp"是“&”符號的HTML表示方法。 在Navigation導航框架運行時,在瀏覽器中URI地址格式為: http://localhost:49750/SilverlightNavigationDemoTestPage.aspx#/About/%E9%93%B6%E5%85%89%E4%B8%AD%E5%9B%BD%E7%BD%91&SilverlightChina.Net 通過URI地址映射解析,其實際地址將指向到"/Views/About.xaml?name=%E9%93%B6%E5%85%89%E4%B8%AD%E5%9B%BD%E7%BD%91&url=SilverlightChina.Net" ![](https://box.kancloud.cn/2016-03-18_56eb67d0aee2e.gif) **讀取“QueryString參數”方式傳遞參數值** Silverlight Navigation導航框架完成參數傳遞后,其目的頁面,需要使用NavigationContext對象中的QueryString屬性讀取當前URI中包含的傳遞參數名稱,以獲取其參數值。其基本格式如下: object parameter = this.NavigationContext.QueryString["parameter"]; 以上面兩個例程而言,其讀取參數格式如下: ~~~ protectedoverridevoid OnNavigatedTo(NavigationEventArgs e) { if (this.NavigationContext.QueryString.ContainsKey("parameter")) { tbReceiveParameter.Text ="接收到的傳遞參數值:"+this.NavigationContext.QueryString["parameter"]; } else { tbReceiveParameter.Text ="接收參數1: "+this.NavigationContext.QueryString["name"]+" 接收參數2:"+this.NavigationContext.QueryString["url"]; } } ~~~ 在使用NavigationContext讀取參數時,有以下兩點需要注意: - 讀取參數前需要檢測參數名稱是否存在,如果NavigationContext.QueryString中不存在需要獲取的參數名稱,則應用會出現異常;而參數值允許為空,如果參數值空,則返回Null到頁面。常用檢測代碼如下:NavigationContext.QueryString.ContainsKey(paramName) - 參數賦值前需要進行參數類型轉換,因為參數傳遞是以字符串形式傳遞,而頁面賦值時則需要根據需求進行值類型轉換,否則應用會出現異常;常用類型轉換代碼如下:int.TryParse(NavigationContext.QueryString[paramName], out paramValue) 最后,從MSDN轉一個URI地址映射解析匹配對照表,其中包括URI附帶參數實例: ![](https://box.kancloud.cn/2016-03-18_56eb67d0bfcb0.gif) 今天講到這里,如果您有問題,歡迎留言討論。 [源代碼下載](http://www.silverlightchina.net/uploads/soft/110809/1-110P91IU3.rar) [Silverlight實例教程系列 - Silverlight Validation驗證實例](http://silverlightchina.net/html/zhuantixilie/getstart/2010/0924/2035.html) [Silverlight實例教程系列 - Silverlight Out-of-Browser實例](http://silverlightchina.net/html/zhuantixilie/getstart/2010/0809/1709.html) [Silverlight實例教程系列 - Expression Blend實例中文教程](http://silverlightchina.net/html/zhuantixilie/getstart/2010/0409/978.html) 歡迎大家加入“專注Silverlight”QQ技術群,歡迎大家加入一起學習討論Silverlight&WPF&Widnows Phone開發技術。 22308706(一群) 超級群500人 37891947(二群) 超級群500人 100844510(三群) 高級群200人 32679922(四群) 超級群500人 23413513(五群) 高級群200人 32679955(六群) 超級群500人 61267622(七群) 超級群500人 88585140(八群) 超級群500人 128043302(九群 企業應用開發推薦群) 高級群200人 101364438(十群) 超級群500人 68435160(十一群 企業應用開發推薦群)超級群500人
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看