Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:53:49+00:00 2026-05-25T02:53:49+00:00

I am using an MVVM pattern on WPF4, though I am new to both.

  • 0

I am using an MVVM pattern on WPF4, though I am new to both. I am looking for a good solution to using a WebBrowser control that can receive Javascript commands and communicate with the ViewModel. It needs the following:

  1. Ability to collect values from Javascript forms, and return them to the ViewModel
  2. Use Javascript to determine ReadyState before
  3. Running Javascript commands (setting form values, use form values for logical steps, submit form) some which happen across multiple page loads

The site being worked on is not under my control to edit or update. It makes heavy use of ActiveX and will not accept non-IE browsers (Awesomium will not work), so the standard WPF WebBrowser control is likely the only option.

This question provides a solution to binding the source of a browser control with an attached property. I think this could be adapted to use the navigate method to send javascript, though I am not sure how values could be returned to the Viewmodel. This is the major hurdle I need to get over.

Heavy Edit – Question receiving very low views and no answers, completely reworded

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:53:49+00:00Added an answer on May 25, 2026 at 2:53 am

    Well if you were working with the site developers to create a solution for your application, then you would use ObjectForScripting to communicate between JavaScript and the app. There a good article here, and another question which might be helpful here.

    However as I understand your question, the site is an arbitrary third party site with no affiliation to your application, and you want to auto-fill some form values and submit the form within your code.

    To do this you can handle the LoadCompleted event of the WebBrowser. This is called when the loaded document readyState is changed to completed. You can therefore use this event as a hook to then set/read the document form values. Note you will need to add a reference to Microsoft mshtml in the project.

    The following is an MVVM style (PRISM) command, which allows an event to bind directly to the ViewModel using behaviors. This is equivalent to registering an event handler in code-behind.

    public ICommand LoadCompleted
    {
        get
        {
            return new EventToCommandWithSender<NavigationEventArgs>(
                (s,e) => { 
    
                   WebBrowser browser = (WebBrowser) sender;
                   // false if nested frame
                   if (e.IsNavigationInitiator)
                   {
                       mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)browser.Document;
                       // always completed
                       var readyState = doc.readyState;
                       // populate form
                       var name = doc.body.document.getElementById("username");
                       name.value = "@TheCodeKing";
                       // submit form
                       var submit = doc.body.document.getElementById("submit");
                       submit.Click();
                    }
            });
        }
    }
    

    Unfortunately the NavigationEventArgs don’t provide a way to access the HTML document or request data. It does contain a WebRequest property but this has not been implemented, and will always be null. In my example I’ve assumed a custom EventToCommandWithSender class which providers the sender as well as the event ARGs when the event fires, but it’s down to your own implementation to get access to the sender.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m building a WPF application using MVVM pattern (both are new technologies for me).
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I'm pretty new to WPF and using the MVVM design pattern. To help learn
I am using the MVVM pattern, I have a view which creates a new
In a WPF app that I'm writing using the MVVM pattern, I have a
I have a Silverlight app that is using the MVVM pattern. I have a
I am building a WPF app that is based on the MVVM pattern (using
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I'm developing a project using the MVVM pattern in WPF. One of the key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.