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

时间:2009-12-02 03:59:34

标签: c# wpf popup opacity

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;

怎么做?

2 个答案:

答案 0 :(得分:12)

您应该启用Popup以获得透明度。添加以下代码行。

popUpControl.AllowsTransparency=true;

答案 1 :(得分:6)

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

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