Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to add WPF controller to a Winform dinamically??

How to add WPF controller to a Winform dinamically??

Scheduled Pinned Locked Moved WPF
helpcsharpwpftutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saku69
    wrote on last edited by
    #1

    Hello evveryone, I am trying to add my WPF controller to a winform dynamically. Could anyone please help me? This is what I tried so fare

    MyWinForm myForm = new MyWinForm();
    WpfUserControl uc = new WpfUserControl();

      if (ListBox.SelectedItem != null)   
        {   
           WPFObject selObject = Listbox.SelectedItem as WPFObject;                   
           uc.GetObjects(selObject);   
           **myForm.Controls.Add(uc);**   
           myForm.Visible = true;                   
        }     
    

    it throws an error. cannot convert WpfUsercontrol to System.Windows.Forms.Control. Is there a way to add WPF controller dynamic to a winform?? many thanks in advance!

    A 1 Reply Last reply
    0
    • S saku69

      Hello evveryone, I am trying to add my WPF controller to a winform dynamically. Could anyone please help me? This is what I tried so fare

      MyWinForm myForm = new MyWinForm();
      WpfUserControl uc = new WpfUserControl();

        if (ListBox.SelectedItem != null)   
          {   
             WPFObject selObject = Listbox.SelectedItem as WPFObject;                   
             uc.GetObjects(selObject);   
             **myForm.Controls.Add(uc);**   
             myForm.Visible = true;                   
          }     
      

      it throws an error. cannot convert WpfUsercontrol to System.Windows.Forms.Control. Is there a way to add WPF controller dynamic to a winform?? many thanks in advance!

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      You cannot directly use a WPF control in WinForms. You will need to use an ElementHost[^] e.g. ElementHost elhost = new ElementHost(); elhost.Size = new Size(110, 60); elhost.Location = new Point(45,35); MyWPFControl wpfctl = new MyWPFControl(); elhost.Child = wpfctl; myForm.Controls.Add(elhost); See here[^]

      S 1 Reply Last reply
      0
      • A ABitSmart

        You cannot directly use a WPF control in WinForms. You will need to use an ElementHost[^] e.g. ElementHost elhost = new ElementHost(); elhost.Size = new Size(110, 60); elhost.Location = new Point(45,35); MyWPFControl wpfctl = new MyWPFControl(); elhost.Child = wpfctl; myForm.Controls.Add(elhost); See here[^]

        S Offline
        S Offline
        saku69
        wrote on last edited by
        #3

        Thank you very much, It was very heplfull

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups