Telerik blogs

As most of you may already know, .NET Framework 3.0 has officially been released. Personally, I think WPF is great. I can't wait to see the final versions of Expression Interactive Designer and VS 2005 extensions for .NET 3.0.
 
You can download it, check it, and admire its potential. Once the admiration starts fading away, you may ask yourself "now what?". You may start writing applications from scratch, you may start migrating existing WinForms applications, or you may decide to wait for the final versions of Expression Interactive Designer and Visual Studio Orcas. You may even decide to wait till Windows Vista ships out (which is also official now).

Whatever your decision, our role as a component vendor is to make your transition easier, especially when it comes to using r.a.d.controls for WinForms. We tested several scenarios and finally came to the conclusion that the best way to use our WinForms controls in a WPF app is by using user controls. For example we did the following five steps in order to use our RibbonBar control in a WPF app:
1) We created a solution with one WPF application and one Class Library project.
2) In the Class Library project we added a new User Control, placed the RibbonBar control there and configured it.
3) In the WPF app project we added the following three namespace declarations to the Window tag in the Window1.xaml file:
    <Window ....
        ....
        xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        xmlns:user="clr-namespace:RadUserControls;assembly=RadUserControls"
>
"RadUserControls" is the namespace in which the user control which holds the RibbonBar resides and is also the assembly name.
4) In the WPF app project we added references to the System.Windows.Forms assembly and to the WindowsFormsIntegration assembly.
Usually the WindowsFormsIntegration assembly can be found in "C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0".
5) Then in the Window1.xaml file we'd created we placed the following lines in order to host the user control:
    <wfi:WindowsFormsHost>
        <user:UserControl1 x:Name="control1" />
    </wfi:WindowsFormsHost>

 
The advantage of using user controls rather than hosting our controls directly in the WindowsFormsHost is that you keep the design time experience to which you should be so used by now from working with controls in WinForms applications. You can add ImageLists, other components and so on, instead of hosting each control / component in a separate host.
You can download the solution from the WinForms Code Library.
We will be eager to hear comments from early adopters of WPF. How do you get started with the new framework? How does the provided solution help you and how would you like us to extend it? Taking small steps at a time we are dedicated to provide developers with seamless migration towards WPF.


About the Author

Hristo Kosev

 

Comments

Comments are disabled in preview mode.