Does WPF Work with C++? Does WPF Work with C++? wpf wpf

Does WPF Work with C++?


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.


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.


Noesis gui can run WPF UIs in c++. You will have to adapt the c# classes to c++ (using their reflection macros, etc). Some controls aren't supported, but it is quite elegant.

For example, WPF might generate :

MainWindow.xaml.cs

using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Media;using System.Windows.Shapes;using System.Windows.Input;namespace BlendTutorial{    /// <summary>    /// Interaction logic for MainWindow.xaml    /// </summary>    public partial class MainWindow : Window    {        public MainWindow()        {            this.InitializeComponent();        }        private void AddButton_Click(object sender, RoutedEventArgs e)        {        }        private void RemoveButton_Click(object sender, RoutedEventArgs e)        {        }        private void ContainerBorder_MouseDown(object sender, MouseButtonEventArgs e)        {        }        private void RadioButton_Checked(object sender, RoutedEventArgs e)        {        }    }}

Then, you would convert it to c++ :

namespace BlendTutorial{class MainWindow final: public Window{public:    MainWindow()    {        InitializeComponent();    }private:    void InitializeComponent()    {        Noesis::GUI::LoadComponent(this, "MainWindow.xaml");    }    bool ConnectEvent(BaseComponent* source, const char* event, const char* handler) override    {        NS_CONNECT_EVENT(Button, Click, AddButton_Click);        NS_CONNECT_EVENT(Button, Click, RemoveButton_Click);        NS_CONNECT_EVENT(Border, PreviewMouseLeftButtonDown, ContainerBorder_MouseDown);        NS_CONNECT_ATTACHED_EVENT(ToggleButton, Checked, RadioButton_Checked);        return false;    }    void AddButton_Click(BaseComponent*, const RoutedEventArgs&)    {    }    void RemoveButton_Click(BaseComponent*, const RoutedEventArgs&)    {    }    void ContainerBorder_MouseDown(BaseComponent*, const MouseButtonEventArgs&)    {    }    void RadioButton_Checked(BaseComponent*, const RoutedEventArgs&)    {    }    NS_IMPLEMENT_INLINE_REFLECTION(MainWindow, Window)    {        NsMeta<TypeId>("BlendTutorial.MainWindow");    }};

More info here : https://www.noesisengine.com/docs/Gui.Core.BlendTutorial.html

They have some pretty nifty stuff if you want to go ham with data models, bindings and mvvp. Or you can just hook up lambdas to control events.

It is a paid framework, though it's free for less than €100K yearly income.