{"id":662,"date":"2015-04-30T10:20:00","date_gmt":"2015-04-30T10:20:00","guid":{"rendered":"https:\/\/staging.infragistics.com\/blogs\/?p=662"},"modified":"2025-02-25T14:07:03","modified_gmt":"2025-02-25T14:07:03","slug":"converting-winforms-to-wpf","status":"publish","type":"post","link":"https:\/\/www.infragistics.com\/blogs\/converting-winforms-to-wpf","title":{"rendered":"Converting WinForms to WPF: Should You Consider It?"},"content":{"rendered":"\n<p>WinForms has long been a popular way to develop form and GUI based applications, generally for Windows based devices. Part of the .NET framework, and originally seen as a replacement for Microsoft Foundation Class Library (MFC), WinForms applications are \u2018event driven\u2019. That is they sit and wait for a user to interact with them, before springing into action and reacting to this input.<\/p>\n\n\n\n<p>Whilst still a useful technology for many (we offer a <a href=\"https:\/\/www.infragistics.comhttps\/\/www.infragistics.com\/products\/windows-forms\" target=\"_blank\" rel=\"noopener noreferrer\">whole range<\/a> of useful and popular controls) WinForms is officially a technology in \u2018maintenance mode\u2019. According to Microsoft, the product is no longer subject to active development, won\u2019t be seeing any new features in the future, but will benefit from bug fixes.<\/p>\n\n\n\n<p>With that in mind, what is the argument for converting a WinForms app to a more modern technology like Windows Presentation Foundation (WPF)? In this post we will take a look at this topic, weighing up the various options and pros and cons.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/community\/cfs-filesystemfile\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/devtoolsguy\/5556.shutterstock_5F00_143889433.jpg\" alt=\" converting a WinForms app to a more modern technology like Windows Presentation Foundation (WPF)\" title=\"converting a WinForms app to a more modern technology like Windows Presentation Foundation (WPF)\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"windows-presentation-foundation\">Windows Presentation Foundation<\/h2>\n\n\n\n<p>Windows Presentation Foundation is a different API for building GUIs. Separate to WinForms, but also included in the .NET Framework, it is based on DirectX and uses a language called XAML to describe its components and elements. Many developers often ask the question: \u201cCan I easily convert my WinForms app?\u201d Let us look at some useful answer and pointers:<\/p>\n\n\n\n<p><b>1. A chance to improve your code<\/b><\/p>\n\n\n\n<p>After deciding to \u2018convert\u2019 your WinForms app to WPF, take a step back and decide if the best approach isn\u2019t to simply rewrite your code from scratch. Undoubtedly you will learn a lot during the process, and the end result will most likely be altogether better code. Switching from WinForms to WPF does involve a change in mindset, <a href=\"https:\/\/rachel53461.wordpress.com\/2012\/10\/12\/switching-from-winforms-to-wpfmvvm\/\" target=\"_blank\" rel=\"noopener noreferrer\">this article<\/a> looks at how your approach should differ. WPF is at its core very different to WinForms, understanding the basics of WPF before you start to migrate any code is a vital step.<\/p>\n\n\n\n<p><b>2. Converting C#.NET WinForms designer code <\/b><\/p>\n\n\n\n<p>If you are looking for a more \u2018automated\u2019 approach, there are utilities that will convert C#.NET designer code to XAML. <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><a href=\"http:\/\/www.win2wpf.com\/\" target=\"_blank\" rel=\"noopener\">This one<\/a>\u00a0is a good example, though we do advise having a good manual check over the code as well.<\/span> <a href=\"http:\/\/wf2wpf.codeplex.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">This CodePlex project<\/a> is also capable of handling basic conversion, taking basic WinForms Form Controls and even carrying over event handling code. Beware the project hasn\u2019t been updated for a number of years. A more up to date option can be found <a href=\"http:\/\/www.ingeniumsoft.com\/Products\/WinForm2XAML\/tabid\/63\/language\/en-US\/Default.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>, and this tool does come with support for a number of different controls.<\/p>\n\n\n\n<p><b>3. Hosting WinForms inside a WPF application <\/b><\/p>\n\n\n\n<p>Rather than converting an entire application, it is possible to reuse WinForms code by hosting controls inside a WPF application. <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms750944.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Microsoft offer<\/a><span style=\"text-decoration: underline;\">s<\/span> a very detailed walkthrough on hosting WinForms composite controls inside a WPF application.<\/p>\n\n\n\n<p><b>4. Validating the results <\/b><\/p>\n\n\n\n<p>If you are new to WPF, or converting\/porting code over from WinForms, then it is a good idea to double check the final results. Some useful tools to do this include:<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Last updated a few years ago, <a href=\"http:\/\/snoopwpf.codeplex.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Snoop<\/a> is however still a useful way to visually debug WPF apps.<\/li>\n\n\n\n<li><a href=\"http:\/\/blog.wpfwonderland.com\/2008\/10\/08\/shazzam-wpf-pixel-shader-effect-testing-tool-now-available\/\" target=\"_blank\" rel=\"noopener noreferrer\">Shazzam<\/a> helps to testing WPF pixel shaders<\/li>\n\n\n\n<li>Any good .NET developer will know about <a href=\"http:\/\/www.red-gate.com\/products\/dotnet-development\/reflector\/\" target=\"_blank\" rel=\"noopener noreferrer\">Reflector<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Microsoft_Blend\" target=\"_blank\" rel=\"noopener noreferrer\">Microsoft Blend<\/a> started life as a stand-alone user interface tool, but is now part of Visual Studio. Either way it is an interesting way of designing WPF apps, and can be a useful aid for those moving from WinForms.<\/li>\n\n\n\n<li>The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa969767.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">WPF Performance Suite<\/a> helps to analyze the behaviour of WPF apps, and provides a means to implement improvements. Useful for those starting out with WPF or refactoring code form WinForms apps.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"multiple-options\">Multiple options<\/h2>\n\n\n\n<p>As experienced developers will know, the .NET framework offers a number of methods and solutions to solving any given problem. When it comes to GUI applications WinForms and WPF are both still very much valid choices, and as we have seen in this post there are means to convert between the two approaches. Whatever the route taken, Infragistics offers a range of <a href=\"\/products\" target=\"_blank\" rel=\"noopener noreferrer\">pre-built UI components<\/a> to help make the final results even more impressive.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"\/cashflow-dashboard\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"\/community\/cfs-filesystemfile.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/devtoolsguy.Cashflow_5F00_Dashboard\/6864.GetTheCode_5F00_WF_5F00_728x90.jpg\" alt=\" \"\/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>WinForms has long been a popular way to develop form and GUI based applications, generally for Windows based devices. Part of the .NET framework, and originally seen as a replacement for Microsoft Foundation Class Library (MFC), WinForms applications are \u2018event driven\u2019. That is they sit and wait for a user to interact with them, before springing into action and reacting to this input.<\/p>\n","protected":false},"author":140,"featured_media":2370,"comment_status":"publish","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-662","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wpf"],"_links":{"self":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/users\/140"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/comments?post=662"}],"version-history":[{"count":4,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/662\/revisions"}],"predecessor-version":[{"id":1946,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/662\/revisions\/1946"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media\/2370"}],"wp:attachment":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media?parent=662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/categories?post=662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/tags?post=662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}