I am working on an application that is for the most part html/javascript (the whole "HTML5" thing) with a light shell of a WPF application so that it can interact with local resources.
The application has a single HTML file which I navigate to programmatically. Once the file is loaded, I am trying to attach event handlers so I can handle specific events in C#.
When I try to use the mshtml objects, it appears that I only get nulls back. For example, here is some code:
string initUrl = "file:///" + Path.Combine(Environment.CurrentDirectory, Path.Combine("Pages", "ComposeSurface.html"));
navBrowser.Navigate(new Uri(initUrl));
navBrowser.Navigated += (o, e2) =>
{
HTMLDocumentClass documentObject = navBrowser.Document as HTMLDocumentClass;
IHTMLElement ele = documentObject.getElementById("initButton");
if (ele != null)
{
Func<IHTMLEventObj, bool> evra = (arg) => { MessageBox.Show("Hello"); return true; };
ele.onclick = evra as object;
}
};
getElementById always seems to return a null, however. I've double checked and the id of the element is consistent.
My second question has to do with handling the event - will this work for a click event from a regular HTML form button as far as attaching some C# to it?