TimBlanch 发表于 2011-11-10 19:53:29

Wpf调色板背景是黑色的

我一直在玩自定义调色板,看看什么会与我的下一个头发纹理的想法。当我将winform用户控件添加到调色板时,一切看起来都像预期的那样,当添加wpf用户控件时,背景是全黑的。按钮或我添加的任何东西看起来都很好,只是背景。下面是我正在使用的代码:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;

namespace Tims_CSharp
{
    class CustomPalette
    {
      public PaletteSet myPaletteSet;
      public PaletteControl controlPalette;
      public wpfPalControl wpfPalette;
      
      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;
            
      }
    }
}

我正在使用vs2010和AutoCAD 2012。
知道为什么会这样吗?再次感谢,
蒂姆
**** Hidden Message *****

huiz 发表于 2011-11-11 13:49:04

可能是因为WPF用于其他东西,比如网站,默认情况下它有一个透明的背景?如果AutoCAD中有白色背景,则颜色是否为白色

tonofsteel 发表于 2011-11-13 16:11:47

请参阅Kean Walmsley的博客文章:http://through-the-interface.typepad.com/through_the_interface/2009/08/hosting-wpf-content-inside-an-autocad-palette.html
我没有尝试与你完全相同的方式,但下面是我在上面的帖子中使用的,我没有发现任何外观问题。主要区别在于下面的代码使用elementhost来保存调色板上的WPF控件:
      
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);//

TimBlanch 发表于 2011-11-13 20:20:29

我试着改变AutoCAD的背景颜色。没什么区别。
tonofsteel -这就对了,谢谢。

tonofsteel 发表于 2021-9-9 17:15:26

为了跟进这篇文章,我在使用WPF作为AddVisual()或使用ElementHost()时遇到了相同的问题,正如本文中的博客文章所述。两者都不作为透明背景,继承了基于主题“亮/暗”的默认调色板颜色
我找到了另一种解决方案,将调色板颜色设置为与主题相同,并将其发布在这里:
https://www.theswamp.org/index.php?topic=47877.0
页: [1]
查看完整版本: Wpf调色板背景是黑色的