我有一个动态生成的超链接,点击时应该打开一个莲花笔记文档。我用下面的代码来做。Silverlight InvalidOperationException点击链接时
HyperlinkButton hlb = new HyperlinkButton();
hlb.SetBinding(HyperlinkButton.ContentProperty, new Binding("Properties[" + col.DisplayField + "]"));
hlb.SetBinding(HyperlinkButton.NavigateUriProperty, new Binding("Properties[" + col.LinkField + "]"));
hlb.Click += new RoutedEventHandler(hlb_Click);
RootGrid.Children.Add(hlb);
这是单击链接时触发的代码。
static void hlb_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton hlb = (HyperlinkButton)sender;
var hostingWindow = HtmlPage.Window;
hostingWindow.Navigate(hlb.NavigateUri);
}
Lotus Notes文档正确打开,但我得到一个System.InvalidOperationException,其细节在下面给出
Description: Failed to navigate to notes://<path to the document>
Stacktrace:
at MS.Internal.NavigationHelper.Navigate(Boolean checkUserInitiatedAction)
at System.Windows.Controls.HyperlinkButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
另一个有趣的事情要注意的是,它是在另一个线程,因此上调在启动hostingWindow.Navigate方法时不会被捕获。
任何想法?
的原因,我不能只让超链接按钮做导航是不是要去正规网址它去Lotus Notes文档(这是形式 笔记:// <路到文档>)。在Silverlight超链接按钮点击不支持这种形式的目标网址。是的,您的代码中发生异常是正确的。并且因为它发生在另一个线程上,所以只能在App.xaml.cs中捕获,而不是实际调用hostingWindow.Navigate(hlb.NavigateUri);导致导航。 –
那么,为什么不使用看起来像超链接按钮的其他类型的控件,并且将事件处理程序攻击为click事件。 – Bryant