locked
WPF: Is it Possible to Add .NET Controls into WPF RRS feed

  • Question

  • Hi,
    I'm trying to add a custom .NET control to a WPF application.  Is this possible? 

    Example:  I have a control called MyControl (contained in MyControl.dll) that I want to add to a WPF Application.  Can this be accomplished and if so, how?

    thanks,

     - Mike
    Tuesday, August 18, 2009 6:33 PM

Answers

  • Whoops, sorry.. left out the major part!  It has to be wrapped in a windows forms host... check out this link:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx
    • Proposed as answer by Nick Teeter Tuesday, August 18, 2009 7:42 PM
    • Marked as answer by Bruce.Zhou Friday, August 21, 2009 4:18 AM
    Tuesday, August 18, 2009 7:42 PM

All replies

  • Add MyControl.dll as a reference in the project and then add it as a namespace in your window...

    xmlns:mc="clr-namespace:blahblah:assembly=MyControl"

    blahblah being the namespace in the .dll you are wishing to reference.  Then add it to your application as usual...

    <this:MyDotNetControl />
    • Proposed as answer by Nick Teeter Tuesday, August 18, 2009 6:40 PM
    Tuesday, August 18, 2009 6:39 PM
  • Thanks,
    The issue I had was that I was trying to place my control inside the <GRID>.  My next question is, do I have to call something to instantiate my control.  When I run the application, I just get a blank window without my control.  Below is my XAML script and I have not done anything in the .cs

    <

     

    Window x:Class="PlayWPFApp.Window1"

     

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

    xmlns:u="clr-namespace:FactMES.Controls;assembly=FactMES.Controls.Utilization"

     

    Title="Window1" Height="768" Width="1024">

     

     

    <u:UtilizationControl AutoLoginUser="False" AutoLogonEnt="False" Height="600" Width="600"/>

    </

     

    Window>

    Tuesday, August 18, 2009 7:29 PM
  • Whoops, sorry.. left out the major part!  It has to be wrapped in a windows forms host... check out this link:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx
    • Proposed as answer by Nick Teeter Tuesday, August 18, 2009 7:42 PM
    • Marked as answer by Bruce.Zhou Friday, August 21, 2009 4:18 AM
    Tuesday, August 18, 2009 7:42 PM
  • Thanks a lot - that did the trick =D
    Tuesday, August 18, 2009 8:03 PM