简体   繁体   English

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

[英]Opacity is not getting applied to the WPF Popup control

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;

How to do it? 怎么做?

You should Enable Popup to have Transparency. 您应该启用Popup以获得透明度。 Add following line of code. 添加以下代码行。

popUpControl.AllowsTransparency=true;

You need to set the opacity on the popup content. 您需要在弹出内容上设置不透明度。
So for your button have 所以对于你的按钮了

popUp.Child = new Button() 
{
    Width = 300,
    Height = 50,
    Background = Brushes.Gray,
    Opacity = 0.5 // set opacity here
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM