Ben Ben - 1 year ago 350
jQuery Question

Can you use jQuery in WPF Applications?

I have been creating a WPF Application over the past few months and I wanted to add abit of animation to my Application.I have been told before that jQuery is a good Javascript library to use for animation.

The problem is after looking around abit there are not many things on the internet that lets me know if this is possible.

I'm very new to jQuery so i wont know much. If jQuery isnt possible in WPF, what is?

Answer Source

So technically you can use jQuery in WPF. Just not in a way that you might necessarily like. With the web browser control you could load html, css, and javascript from local or remote sources.

Please note* I did not make this example up from scratch. It comes from this site

in xaml add the control

<WebBrowser x:Name="wbMain" Margin="30"></WebBrowser>

and in code

wbMain.Navigate(new Uri("c:/MyFileThatUsesJqueryAndHasJqueryAsARef.htm"));

Additionally communication between the two is also possible but does require a bit of work. You would have to create a com visible class with full trust security

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public class ObjectForScriptingHelper
    Mainwindow mExternalWPF;
    public ObjectForScriptingHelper(Window1w)
        this.mExternalWPF = w;
    public void InvokeMeFromJavascript(string jsscript)
        this.mExternalWPF.tbMessageFromBrowser.Text = string.Format("Message :{0}", jsscript);


With that you would create an instance in your class and access it via javascript like

<input type="text" id="txtMessage" />
<input type="button" value="InvokeMe" onclick="javascript:window.external.InvokeMeFromJavascript(document.getElementById('txtMessage').value);" />

Please look at the article for even more stuff you can do.


  • This is more than likely not the best way to go for a new desktop application. If its just a matter of using an existing tool out of familiarity then I'd consider other avenues of approach like learning WPF or looking to something like this question or one of these

If in fact you are out to use as much of an existing code base coded in html and javascript with with an offline app you could utilize this approach to recycle your existing code base by all means look at this or method or one of the other methods mentioned like using WPF animations.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download