你能在WPF应用程序中使用jQuery?能在、应用程序、WPF、jQuery

2023-09-03 03:00:28 作者:想住进你的梦里

我一直在创造一个WPF应用程序在过去的几个月中,我想添加动画升技我Application.I已被告知,jQuery是一个很好的JavaScript库使用动画之前。

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.

我很新的jQuery的,所以我不会知道的不多。如果jQuery的WPF中心不是可能的,又是什么?

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

推荐答案

因此​​从技术上讲,你可以在WPF中使用jQuery。只要不是在你可能不一定喜欢的方式。 随着 Web浏览器控件< /一>您可以加载HTML,CSS和JavaScript从本地或远程数据源。

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

在XAML添加控件

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

在code

and in code

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

此外,两者之间的沟通也是可能的,但确实需要一些工作。 你将不得不以完全信任的安全创建一个COM可见的类

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")]
[ComVisible(true)]
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);
    }

}

使用,你会创建一个像

<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.

注意事项

这是比可能不会去一个新的桌面应用程序的最佳途径。如果使用现有的工具进行熟悉它只是一个问题,然后我会考虑的方法等途径,就像学习WPF或寻找到像this问题或 之一的的 这些 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

如果事实上你外出使用尽可能多的现有code碱基codeD的HTML和JavaScript与离线应用程序,你可以利用这种方法,所有回收现有的code基指看这个或方法,或像使用的 WPF动画的。

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.