TheSwamp

Code Red => .NET => Topic started by: TimBlanch on November 10, 2011, 07:53:29 PM

Title: Wpf Palette background is black
Post by: TimBlanch on November 10, 2011, 07:53:29 PM
I have been playing with custom palettes and seeing what would work with my next hairbrained idea. When I add a winform user control to a palette everything looks as expected, when adding a wpf user control the background is all black. The buttons or whatever I add look fine it's just the background. Here is the code I am using:
Code: [Select]
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;

[assembly:CommandClass(typeof(Tims_CSharp.CustomPalette))]

namespace Tims_CSharp
{
    class CustomPalette
    {
        public PaletteSet myPaletteSet;
        public PaletteControl controlPalette;
        public wpfPalControl wpfPalette;

        [CommandMethod("palSet")]
        public void SamplePalette()
        {
            if (myPaletteSet == null)
            {
                myPaletteSet = new PaletteSet("MyPalette", new System.Guid("ABF3806E-DA13-4827-80FB-29D3F10952BE"));
                controlPalette = new PaletteControl();
                wpfPalette = new wpfPalControl();
                myPaletteSet.Add("Custom Palette", controlPalette);
                myPaletteSet.AddVisual("WPF Palette", wpfPalette);
            }
            myPaletteSet.Visible = true;
           
        }
    }
}

I am using vs2010 and AutoCAD 2012.
Any ideas why this is happening?

Thanks again,

Tim
Title: Re: Wpf Palette background is black
Post by: huiz on November 11, 2011, 01:49:04 PM
Probably because WPF is used in other things like websites, and it has a transparent background by default? If you have a white background in AutoCAD, is the color white then?
Winform objects do have a form background as default I assume, so they are nicely grey.
Title: Re: Wpf Palette background is black
Post by: tonofsteel on November 13, 2011, 04:11:47 PM
See Kean Walmsley Blog Post: http://through-the-interface.typepad.com/through_the_interface/2009/08/hosting-wpf-content-inside-an-autocad-palette.html (http://through-the-interface.typepad.com/through_the_interface/2009/08/hosting-wpf-content-inside-an-autocad-palette.html)

I did not try the same exact way you are, but the following is what I used from the above post and I did not find any problem with appearance.  The main difference is that the below code uses an elementhost to hold the WPF control on the palette:

Code: [Select]
       
UserControl1 uc2 = new UserControl1();  //WPF User control
ElementHost host = new ElementHost();
host.AutoSize = true;
host.Dock = DockStyle.Fill;
host.Child = uc2;
_ps.Add("Add ElementHost", host);  //
Title: Re: Wpf Palette background is black
Post by: TimBlanch on November 13, 2011, 08:20:29 PM
Huiz - I tried changing AutoCAD's background color. It didn't make any difference.

tonofsteel - that did the trick, thanks.
Title: Re: Wpf Palette background is black
Post by: Steve Hill on September 09, 2021, 05:15:26 PM
To follow up on this post, I had the same issue when using WPF as AddVisual() or using ElementHost() as mentioned on the blog post in this feed. Neither worked as transparent background inheriting the default palette color based on the theme light/dark.

I found another solution that sets the palette color to the same as the theme and posted it here:
https://www.theswamp.org/index.php?topic=47877.0 (https://www.theswamp.org/index.php?topic=47877.0)