不透明度未应用于 WPF Popup 控件

Posted

技术标签:

【中文标题】不透明度未应用于 WPF Popup 控件【英文标题】:Opacity is not getting applied to the WPF Popup control 【发布时间】:2010-12-22 06:45:15 【问题描述】:
Popup popUpControl = new Popup();

popUpControl.PlacementTarget = this; 
popUpControl.StaysOpen = true;
popUpControl.Child = new MyUserControl(); /// my user control 
popUpControl.Opacity = 0.5; // this code has no effect in the appearance of the popup
popUpControl.IsOpen = true;

怎么做?

【问题讨论】:

【参考方案1】:

您应该启用弹出窗口以具有透明度。添加以下代码行。

popUpControl.AllowsTransparency=true;

【讨论】:

嗨 Sasikumar,感谢您的回复.. 我尝试过但仍然无法正常工作.. 请将以下代码放入 wpf 测试应用程序中,然后查看 Popup poUp = new Popup(); poUp.PlacementTarget = 这个; poUp.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; poUp.StaysOpen = true; poUp.PopupAnimation = PopupAnimation.Scroll; poUp.VerticalOffset = 52; poUp.Horizo​​ntalOffset = 5; poUp.Child = new Button() Width = 300, Height = 50, Background = Brushes.Gray; poUp.AllowsTransparency = true; 杰是对的。您需要指定内容的不透明度。尝试添加一个网格作为子项以弹出并在此网格中添加所有控件。配置网格的不透明度以将其反映在其子项中。【参考方案2】:

您需要设置弹出内容的不透明度。 所以对于你的按钮有

popUp.Child = new Button() 

    Width = 300,
    Height = 50,
    Background = Brushes.Gray,
    Opacity = 0.5 // set opacity here
;

【讨论】:

以上是关于不透明度未应用于 WPF Popup 控件的主要内容,如果未能解决你的问题,请参考以下文章

设置 WPF 标签内容 Alpha 透明度而不是整个控件的不透明度

WPF 渲染颜色与画笔和控件元素上的不透明度不一致

在 WPF 中使用另一个控件作为不透明蒙版?

在WPF中使用另一个控件作为不透明蒙板?

如何在WPF控件上应用简单的褪色透明效果?

在 Loaded 事件中未完成渲染