【发布时间】:2012-02-21 13:57:33
【问题描述】:
我在 aspx 页面中使用 silverlight 内容。我创建的 silverlight 页面位于一个单独的 silverlight 项目中,我已将该项目添加到我的普通 asp.net 应用程序 ClientBin。我需要重定向到我的 aspx 页面从 silverlight 页面按钮单击 asp.net 项目。我怎样才能做到这一点?
【问题讨论】:
标签: asp.net silverlight
我在 aspx 页面中使用 silverlight 内容。我创建的 silverlight 页面位于一个单独的 silverlight 项目中,我已将该项目添加到我的普通 asp.net 应用程序 ClientBin。我需要重定向到我的 aspx 页面从 silverlight 页面按钮单击 asp.net 项目。我怎样才能做到这一点?
【问题讨论】:
标签: asp.net silverlight
我认为您有两种选择之一。在该 silverlight 控件的视图模型中,在初始化期间,将超链接按钮的导航 URI 绑定到要导航到的所需 URI。选项 2(更流畅):在 click 方法上,在托管 silverlight 对象的页面上调用 javascript 方法。然后,该方法将为您执行某种平滑的 jquery 转换或只是一个简单的导航。
选项一:<HyperlinkButton NavigateUri="{Binding DesiredURL}" TargetName="_blank" />
对于选项 2,请记住包括:
使用 System.Windows.Browser;
选项 2:
public void OnFancyNavigate(string _destination)
{
//call the browser method/jquery method (I used constants to centralize the names of the respective browser methods
try
{
HtmlWindow window = HtmlPage.Window;
window.Invoke(Constants.TBrowserMethods.BM_FANCYNAVIGATE, new object[] { _destination});
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
}
最后,在托管 xap 内容的 aspx/html/.js 文件中定义 javascript 方法:
function fancyNavigate(_destination) {
//some fancy jquery or just the traditional document.location change here
}
当从您的代码中调用时,C# 将定位 javascript 方法,您应该一切顺利
【讨论】: