Showing posts with label silverlight. Show all posts
Showing posts with label silverlight. Show all posts

Thursday, August 9, 2012

WPF MVVM with WinForms Controls

This is the second part of my series on using MVVM with WPF. In the first article I discussed architecting disconnected applications and how MVVM was a great fit for WPF smart clients as well as Silverlight web clients. Now we move on to the process of refactoring an old Windows Forms application to use this new architecture.

The main concern with changing an underlying technology is the initial investment in rewriting code. To help mitigate this issue, WPF has provided a WindowsFormsHost element that allows us to host WinForms controls inside of a WPF Page. Obviously this limits how effectively we can leverage other features provided by WPF, however with a few workarounds it's a viable solution to avoid having to completely rewrite those old WinForms controls.

How easy is it to implement the WindowsFormsHost?
<WindowsFormsHost><wfh:WinFormsUserControl x:Name="LegacyUserControl" /></WindowsFormsHost>

Okay, it's only slightly more complicated than that. You will need to add add a reference to WindowsFormIntegration and possibly System.Windows.Forms (if it is not already referenced).

Now the question comes to how we interact with this control from our ViewModel since we can't use WPF bindings in our WinForms control. We can bridge this gap by adding events to our WinForms user control.


Then we wire up the events to our DataContext in our WPF Page code-behind.


While I generally prefer to avoid using the code-behind, we also don't want our ViewModel to be aware of the internal workings of our View.

The end result is our Windows Forms control interacts with elements in our WPF Page.

demonstration

Download Demo Source Code

Friday, January 23, 2009

Nashville Web Developer January Meeting Review

We had a great turnout for our first meeting and came up with some great suggestions for presentations. Thanks to everyone who participated. Here's a list of the meeting topics we're considering:
- Silverlight & XAML
- Silverlight 3rd Party Components
- ASP.NET Performance Considerations
- ASP.NET Security Considerations
- ASP.NET Page Lifecycle
- Introduction to JQuery
- Ajax/JavaScript Development
- Designing with Cascading Style Sheets (CSS)
- DotNetNuke Installation & Configuration (1/2)
- DotNetNuke Module Development (2/2)
- Overview of Visual Studio 2010
- Converting Classic ASP/ActiveX to ASP.NET
- Search Engine Optimization (SEO)

Joseph Wichman shared his experience creating streaming videos with Silverlight. They can be found in the Research Videos section of tnbackpackers.org.

Friday, January 2, 2009

Silverlight in DotNetNuke

Have you ever been fired up about doing something, but every time you try to start you get bogged down in the details and loose interest? If you're a developer and tinker with projects at home I'm sure this has happened a time or two. I had an idea for a website, similar to Craigslist, but instead of hosting classified ads it would host a calendar of events for motorcycle enthusiasts. If you want to plan a ride to a specific destination next weekend, just go to your city's site and post a ride. Other members can join in if they're interested. It wouldn't be limited just to rides, but also bike rallies and club events.

I brought all the pieces together except one major facet, the event calendar. I used DotNetNuke as a basis for the site and couldn't find a decent event module. The core module didn't display well and was a bit buggy, and on top of the standard limitations I was trying to customize the site so events would tie in with discussion threads. Post an event and an associated thread would be created where people could ask questions and talk about the event. I also saw the need for moderation/abuse reporting, which would need some custom work. Every time I tried to make some headway it seemed I was farther away from my goal.

It's been over a year since I started struggling with the site and tonight I resumed my efforts to get something launched. What makes now different than all the other times? My current client needed a management portal and wanted it created using DotNetNuke. This gave me the opportunity to develop some custom modules in an environment where I was focused with no distractions. The result was some pretty nice modules and a lot of useful experience. I also did some work this summer with Microsoft Silverlight. If you're not familiar with Silverlight, it's similar to Flash in that it's great for making media-rich web interfaces. This is perfect for an interactive calendar. The last piece of the puzzle is Silverlight Desktop for DotNetNuke. It provides the framework for easily including Silverlight applications in a DotNetNuke site.

My goal is to have SOMETHING working by the end of the weekend. It probably wont be very pretty and it surely wont have all the functionality I want, but if I can get something published it should get me out of this rut and help generate some momentum.