Use WPF from Windows Forms projects in Visual Studio 2008

Sign in to queue


Author: Hi, I am Daniel Moth Smiley

Introduction: Windows Forms developers do not need to throw away their code and start from scratch in Windows Presentation Foundation, simply to get a stunning UI for a particular use case of their application. In this 17' video I demonstrate how to get started with interop between WPF and WinForms applications. For more please visit my blog post here.

Video download: Click on the image to play the video (from a streaming file). If you'd prefer to download the wmv packaged in a zip file, you may do so here.



Download this episode

The Discussion

  • User profile image
    It was only because I am particularly interested in this area that i put up with the appalling reliability of the streaming server on fullscreen mode, it would not last more than 2 minutes without losing the connection!
  • User profile image
    Oh c**p... I've just noticed the zip file option...
  • User profile image
    Daniel Moth
    Hi jh71283, I apologise for your bad experience with the streaming servers and I am glad you found the ZIP option... Thanks for persisting.
  • User profile image
    Steve Naughton
    Well done, nicely paced.  Question: why did you disable the Visual Studio Hosting Process?
  • User profile image
    Daniel Moth
    Thanks Steve. The reason was that the pre-release version of VS2008 that I was using had a showstopper bug when I mixed wpf interop with the hosting process. It should be fixed now of course.
  • User profile image
    Cool screencast, thx!
  • User profile image
    Daniel Moth

    kriz, thanks for watching.




  • User profile image

    First THIS WAS great and addressed almost everything I needed.


    I have an issue and dont know how to address it and it was not addressed in the video.

    I hope you or someone can help.

    I placed a UserControl onto my WinForm some of the Xaml is below. If you notice in my user control

    there is a PlusButton_Click how do I attach that to the main form?

    Or how to alter the Winform to be able to handle a click event on the controls? How do I forward this? Its a custom control.




        <Slider Name="slider1" Width="21" Orientation="Vertical" TickFrequency="1" Maximum="5" TickPlacement="None" IsSnapToTickEnabled="True" Value="0" HorizontalAlignment="Left" Margin="1,23,0,17" />
        <Button x:Name="PlusButton" HorizontalAlignment="Left" VerticalAlignment="Top" Width="25"

          Content="+" Height="37" Style="{StaticResource NewUpButton}" Background="#FF1C96FF"

           FontWeight="Black" FontFamily="Arial" FontSize="16"

          Click="PlusButton_Click" />


  • User profile image
    Daniel Moth

    Hi ChicagoBob


    Glad the video was useful. May I suggest that you use the free online forums for WPF questions please:


    Good luck!




  • User profile image

    Hey ChicoBob


    I don't know if you got it figured out yet, but here's my suggestion:


    In the XAML code behind:



     Public Event RemindClick As EventHandler Public Event DismissClick As EventHandler Private Sub dismiss_button_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles dismiss_button.Click RaiseEvent DismissClick(Me, e) End Sub Private Sub remind_button_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles remind_button.Click RaiseEvent RemindClick(Me, e) End Sub 


    Here you're creating 2 event handlers and then raising them on the click event.


    In the code behind on the Windows Form:


     Dim WithEvents WpfControl As WpfControlLibrary.WpfControl= Nothing ' In the form OnLoad event WpfControl = New WpfControlLibrary.WpfControl ElementHost1.Child = WpfControl Private Sub OkClick(ByVal sender As Object, ByVal e As EventArgs) Handles WpfControl.RemindClick ' Some code here End Sub Private Sub CancelClick() Handles WpfControl.DismissClick ' Some code here End Sub 


    Hope that helps...

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.