missbluebar

Hi All,

As the subject suggests I have a html document hosted in a Frame element. I am looking for an event to determine when a hyperlink is clicked in the html document.

The problem being that the Frame.Navigating event only fires when I call frameContent.Navigate(new Uri(..)) not when a hyperlink is clicked in the html document.

I have tried numerous other events on the Frame control; Navigated, NavigatingProgress,etc to no avail could someone tell me correct event

Test app code:

XAML

Code Snippet

<Window x:Class="TestHyperlink.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="TestHyperlink" Height="482" Width="474"

>

<Frame Name="frameContent">

</< FONT>Frame>

</< FONT>Window>

C#

Code Snippet

public Window1()

{

InitializeComponent();

this.frameContent.Navigate(new Uri(@"Test.htm"));

this.frameContent.Navigating += new System.Windows.Navigation.NavigatingCancelEventHandler(frameContent_Navigating);

}

void frameContent_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)

{

System.Diagnostics.Trace.WriteLine(e.Uri.ToString());

}

Html

(The test Html tries to play with the target attribute.)

thx.

miss.b.



Re: Windows Presentation Foundation (WPF) How? Hyperlink click in html hosted in Frame

Drew Marsh

Unfortunately I don't think there's any way to accomplish this with Frame. You will have to switch to use the WebBrowser control from WinForms where you can hook into its Navigating event. Since Frame has the same restrictions as using a WinForms control anyway, this shouldn't have much of an impact on the design of your project.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) How? Hyperlink click in html hosted in Frame

WPCoder

As Drew mentioned, you can't. I recently posted this as a trick to get access to the DOM:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1620731&SiteID=1

It's the same solution -- how to get access to the WinForm version of the WebBrowser from XAML (I posted a tiny sample).

You'll just need to attach to the BeforeNavigation event of the web browser if you want to know when someone clicked (and optionally prevent them).






Re: Windows Presentation Foundation (WPF) How? Hyperlink click in html hosted in Frame

Seth Veale

There is a Navigating event on the Frame class in WPF. Is this something that could be handled in a similar way as in the windows form web browser control

Or perhaps a containing control for the Frame class could handle the navigation





Re: Windows Presentation Foundation (WPF) How? Hyperlink click in html hosted in Frame

Hua Wang

Thanks for your feedback. This is a known limitation. Yes one of the possible solution is to expose through Frame's navigation events.