Author Topic: Hosting WPF content inside an AutoCAD palette  (Read 4010 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Hosting WPF content inside an AutoCAD palette
« on: October 15, 2012, 09:37:36 AM »
I have read this page by Kean Walmsley .

Into Kean's code, he has created a ElementHost instance, and linked it with uc2 variable. If we open other tab, and see ElementHost again - it is incorrect behaviour. ElementHost shall not be displayed on other tabs.

Question: How must I patch it code for correct result?

Best Regards,
Andrey.

BlackBox

  • King Gator
  • Posts: 3770
Re: Hosting WPF content inside an AutoCAD palette
« Reply #1 on: October 15, 2012, 10:48:19 AM »
You must create a new ElementHost() for each tab, and then specify a different UserControl*.xaml for the host's Child Property Object.


Sample adaptation from Kean's post:

Code - C#: [Select]
  1. // Code converted from VB.NET to C# using Telerik
  2.  
  3. [CommandMethod("WPFP")]
  4.  
  5. public void ShowWPFPalette()
  6. {
  7.  
  8.         if (_ps == null) {
  9.                 // Create the palette set
  10.                 _ps = new PaletteSet("WPF Palette");
  11.                 _ps.Size = new Size(400, 600);
  12.                 _ps.DockEnabled = (DockSides)Convert.ToInt32(DockSides.Left) + Convert.ToInt32(DockSides.Right) + Convert.ToInt32(DockSides.Top) + Convert.ToInt32(DockSides.Bottom);
  13.  
  14.                 // Create our first user control instance
  15.                 UserControl1 uc = new UserControl1();
  16.                 ElementHost host1 = new ElementHost();
  17.                 host1.AutoSize = true;
  18.                 host1.Dock = DockStyle.Fill;
  19.                 host1.Child = uc;
  20.                 _ps.Add("Awesome Tab", host1);
  21.  
  22.                 // Create our second user control instance and
  23.                 // host it in an ElementHost, which allows
  24.                 // interop between WinForms and WPF
  25.                 UserControl2 uc2 = new UserControl2();
  26.                 ElementHost host2 = new ElementHost();
  27.                 host2.AutoSize = true;
  28.                 host2.Dock = DockStyle.Fill;
  29.                 host2.Child = uc2;
  30.                 _ps.Add("Developer Tab", host2);
  31.  
  32.         }
  33.  
  34.         // Display our palette set
  35.         _ps.KeepFocus = true;
  36.         _ps.Visible = true;
  37.  
  38. }
  39.  

HTH
« Last Edit: October 15, 2012, 12:47:07 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Hosting WPF content inside an AutoCAD palette
« Reply #2 on: October 15, 2012, 12:09:13 PM »
Thank you.

BlackBox

  • King Gator
  • Posts: 3770
Re: Hosting WPF content inside an AutoCAD palette
« Reply #3 on: October 15, 2012, 12:45:26 PM »
Thank you.

You're welcome; I am happy to help.  :-)
"How we think determines what we do, and what we do determines what we get."