
1.窗口跳转
在App中定义一个GrID控件:
GrID rootGrID = new GrID();
private voID Application_Startup(object sender,StartupEventArgs e)
{
// this.RootVisual = new MainPage();
this.RootVisual = rootGrID;
this.rootGrID.Children.Add(new Login());
}
在App里面写一个方法来解决页面转向:
public voID RedirectTo(UserControl usercontrol)
{
App app=(App)Application.Current;
app.rootGrID.Children.Clear();
app.rootGrID.Children.Add(usercontrol);
}
在xmal调用这个方法:
App app=(App)Application.Current;
// app.variablename = txtUsername.Text.Trim();
app.RedirectTo(new MainPage());
Session是运行在服务器上的,而Silverlight运行在客户端。因此在Silverlight中使用Session的说法并不正确。
有两种方法实现Silverlight与Session的关联:
方法一、通过WCF使用ASP.NET中的Session[因BasichttpBinding不支持WCF中的Session,如使用WCF会话将报错 ]
首先:在web.config中<system.serviceModel >下添加:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
然后:在服务类[不是接口]下添加如下属性:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
接下来就可以使用Session,记得添加System.Web的引用
httpContext.Current.Session["Yourname"] = something;
object something = httpContext.Current.Session["Yourname"];
方法二、在客户端新建一个静态类模拟Session
如要保存登陆信息,可在验证了用户名、密码之后在客户端保存相关信息。
using System;
using System.Collections.Generic;
namespace SessionDemo
{
public static class SessionManager
{
private static Dictionary<string,object> session = new Dictionary<string,object>();
public static Dictionary<string,object> Session
{
get { return SessionManager.session; }
set { SessionManager.session = value; }
}
}
}
使用方法:
赋值:
SessionManager.Session["uname"] = "kunal";
取值:
txbUname.Text = SessionManager.Session["uname"].ToString();
3.参数传递
xaml向aspx :
HTMLWindow HTML = HTMLPage.Window;
string url = "http://localhost:24690/MasterMain.aspx?USERID=" + UserID+"&RolEID="+RoleID;
HTML.Navigate(new Uri(url));
aspx向xaml:
HTML页面中:
<param name="initparams" value="path=GeneratedImages/dzc_output.xml,zoomIn=3" />
App里:
if (e.InitParams != null){
foreach (var data in e.InitParams){
}
}
还可以采用以下直接的方法:把参数直接存在: <input type="hIDden" ID="YouParaname" name="YouParaname" value="YouParaValue" >然后在SL里面:HTMLPage.document.GetElementByID("YouParaname").GetAttribute("value")这样也很方便,而且更容易理解,方便Post到服务器。
总结以上是内存溢出为你收集整理的SL三个基本问题:窗口跳转、变量保存、参数传递全部内容,希望文章能够帮你解决SL三个基本问题:窗口跳转、变量保存、参数传递所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)