Does WPF Work with C++?

2019-01-11 09:20发布

My understanding is that Microsoft Visual Studio was rewritten to use WPF. I'm still not clear on why, but acknowledge my knowledge about WPF is very limited.

My question is if anyone knows how much support WPF has for C++, and if Visual Studio is still written in C++.

Personally, WPF primarily appears to be .NET/VB/C# thing. Is anyone using it with C++?

2条回答
2楼-- · 2019-01-11 09:57

WPF is a .NET technology. Of course it can be used with C++, like any other part of .NET can, but it requires you to jump through some interop hoops, or possibly write it all in C++/CLI. (And you'll have to write a lot of boilerplate code yourself, as the designer doesn't work with C++/CLI.)

And Visual Studio isn't, and probably never was, "written in C++". With 2010, members of the VS team have stated on their blogs that VS is now primarily a managed application. Of course there's still a ton of C++ code in there, and that's not going away any time soon, but a lot of it is C#/VB today.

But that didn't happen overnight. Managed code has gradually been added to Visual Studio with every release. Visual Studio is written in many different languages.

If what you're actually asking is "can I write an addin for Visual Studio using C++", then the answer is "yes".

If you're asking "is it practical to write an application in C++, and still use WPF", the answer is probably "only if you write the WPF code in C#, and then have some interop code binding this together with your C++ app.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-11 10:14

You can use WPF with C++/CLI. It is a .NET API, however, so it requires the .NET Framework.

That being said, the designer support is non-existent with C++. This means that, for practical purposes, WPF doesn't really work with C++.

Typically, the user interface layer is written in C# (or VB.NET), then calls into C++ code, often exposed via P/Invoke or C++/CLI layers. By using C++/CLI, it's very easy to interoperate between C++ code and C#/VB.NET code.

查看更多
登录 后发表回答