单击链接时出现 Silverlight InvalidOperationException

发布于 2024-12-08 12:40:14 字数 1386 浏览 4 评论 0原文

我有一个动态生成的超链接,单击该超链接应打开一个 Lotus Notes 文档。我使用下面的代码来做到这一点。

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 方法被触发时不会被捕获。

有什么想法吗?

I have a dynamically generated hyperlink which when clicked should open a lotus notes document. I do it using the code below.

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);

this is the code that fires when the link is clicked.

static void hlb_Click(object sender, RoutedEventArgs e)
{
    HyperlinkButton hlb = (HyperlinkButton)sender;
    var hostingWindow = HtmlPage.Window;
    hostingWindow.Navigate(hlb.NavigateUri);
}

the lotus notes document opens correctly but I get a System.InvalidOperationException, the details of which are given below

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)

Another interesting thing to note is that it is raised on another thread and hence is not caught when the hostingWindow.Navigate method is fired.

Any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2024-12-15 12:40:14

使用 Silverlight 5,我将打开 Lotus Notes 文档链接的调用包装在任务中,并且能够打开该链接而不会生成错误。

private void TryOpenDocLink()
{
    TaskScheduler ts = TaskScheduler.Default;

    Task<bool> task = OpenDocLink();

    task.ContinueWith(t =>
    {
        if (t.Exception != null)
        {
            this.SetError(t.Exception.Message, enMessageLevel.Error);
        }
    });
}

private Task<bool> OpenDocLink()
{
    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();

    try
    {
        var hostWindow = HtmlPage.Window;
        hostWindow.Navigate(new Uri(DocLinkPath));
        tcs.SetResult(true);
    }
    catch (Exception)
    {
        tcs.SetResult(false);
    }

    return tcs.Task;
}

Using Silverlight 5, I wrapped the call to open the Lotus Notes doc link within a task and was able to open the link without generating an error.

private void TryOpenDocLink()
{
    TaskScheduler ts = TaskScheduler.Default;

    Task<bool> task = OpenDocLink();

    task.ContinueWith(t =>
    {
        if (t.Exception != null)
        {
            this.SetError(t.Exception.Message, enMessageLevel.Error);
        }
    });
}

private Task<bool> OpenDocLink()
{
    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();

    try
    {
        var hostWindow = HtmlPage.Window;
        hostWindow.Navigate(new Uri(DocLinkPath));
        tcs.SetResult(true);
    }
    catch (Exception)
    {
        tcs.SetResult(false);
    }

    return tcs.Task;
}
稚然 2024-12-15 12:40:14

尝试将点击事件标记为已处理:

static void hlb_Click(object sender, RoutedEventArgs e)
{
    e.Handled = true;
    HyperlinkButton hlb = (HyperlinkButton)sender;
    var hostingWindow = HtmlPage.Window;
    hostingWindow.Navigate(hlb.NavigateUri);
}

我不确定这是否可以解决问题。该错误来自超链接按钮内的单击事件代码。您可以看出这一点,因为该代码使用了 NavigationHelper 类,而 Window.Navigate 方法则没有。

您是否有理由不只让超链接按钮进行导航?

Try marking the click event as handled:

static void hlb_Click(object sender, RoutedEventArgs e)
{
    e.Handled = true;
    HyperlinkButton hlb = (HyperlinkButton)sender;
    var hostingWindow = HtmlPage.Window;
    hostingWindow.Navigate(hlb.NavigateUri);
}

I'm not sure that this will fix the issue. The error is coming from the click event code inside the hyperlink button. You can tell because that code uses the NavigationHelper class while the Window.Navigate method does not.

Is there a reason you're not just letting the hyperlink button do the navigation?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文