Thanks to you all for your posts on this, I was able to figure out a working solution that is dynamic to the Application theme colors, light or dark.
Ultimately, my issue was in using WPF, even the the User Control background was transparent, it did not show up correctly within the palette.
When using AddVisual("MyPalette", Palette, true), it actually came in Black.
Then I ran across this blog stating we should host the WPF with ElementHost to get it to come in properly. That came in, but did not change colors based on the theme.
https://through-the-interface.typepad.com/through_the_interface/2009/08/hosting-wpf-content-inside-an-autocad-palette.htmlThat brought me here to determine a dynamic solution that works across various versions (2015 and up) that pulls in the theme color. To use this solution, you only need to add reference to AdUiPalettes.dll. Thanks to @CADBLOKE for the idea of using DotPeek to look into these assemblies I was able to determine that Autodesk.Windows.Palettes.PaletteThemeDefaults.DarkOverallColor would return the Dark theme color and Autodesk.Windows.Palettes.PaletteThemeDefaults.LightOverallColor would return the light theme. And thanks to @nekitip as I used parts of your code converted over to C#.
public class PaletteSetItem : PaletteSet
{
static PaletteSetItem instance = null;
static Guid guid = new Guid("{f9fead11-f73b-48b3-84c2-bd93b02df9bc}");
const string showCommand = "MyPalette";
private SolidColorBrush backgroundColor; //this is used to store the palette background color if needed
public static MyPalette MyPaletteCtrl { get; set; }
public PaletteSetItem()
: base(showCommand, showCommand, guid)
{
try
{
//Add the icon to the palette
base.Icon = MyIcon;
//Set the Palette size.
base.Size = new Size(400, 800);
//Changing background color based on System variable
//Following ideas here: https://www.theswamp.org/index.php?topic=47877.0
//Using Jetbrains DotPeek on AdUiPalettes was able to identify and pull the PaletteThemeDefaults
//Then converting color to a brush
MyPaletteCtrl = new MyPalette();
//Check theme to set the initial color and the reactors
CheckTheme();
//Set Palette background color
MyPaletteCtrl.Background = backgroundColor;
//Add the palette
base.AddVisual("MyPalette", MyPaletteCtrl, true);
Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
}
catch (Exception ex)
{
//Error loading palette
}
}
protected override void OnPaletteSetClosed()
{
Application.SystemVariableChanged -= new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
}
public static void PaletteSetItemCommand()
{
instance = new PaletteSetItem();
instance.Visible = true;
}
private void variableChanged(object o, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
if (e.Name == @"COLORTHEME" && e.Changed)
CheckTheme();
//Set Palette background color
MyPaletteCtrl.Background = backgroundColor;
}
private void CheckTheme()
{
if (Application.Version.Major > 19)
{
//Background color is set based on the theme color
if (System.Convert.ToInt32(Application.GetSystemVariable(@"COLORTHEME")) == 1)
{
Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.LightOverallColor);
backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
}
else
{
Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.DarkOverallColor);
backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
}
}
else
{
//Sets a default gray color just so there's something
backgroundColor = (SolidColorBrush)new BrushConverter().ConvertFrom(@"#808080");
}
}
}
Of course, you could likely set this up to bind to the WPF User Control, but I chose not to go that route as I think this is more supportive of both WinForms and WPF.
Hope this helps someone else too.