2009-12-02 33 views
4
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; 

如何做到這一點?不透明度不適用於WPF Popup控件

回答

6

您需要設置彈出內容的不透明度。
因此,對於您的按鈕具有

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

謝謝周杰倫.. 它工作:) – Subindev

10

您應該啓用Popup具有透明度。添加下面的代碼行。

popUpControl.AllowsTransparency=true; 
+0

嗨Sasikumar, 感謝名單烏拉圭回合的答覆..我HV試過,但仍然沒有工作.. 請把這個下面的代碼在WPF測試應用程序,看看, 彈出poUp =新的Popup(); poUp.PlacementTarget = this; 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; – Subindev

+0

周杰倫是對的。您需要指定內容上的不透明度。嘗試添加一個網格作爲孩子彈出並添加在這個網格中的所有控件。配置網格的不透明度以反映其子元素。 –

+0

是的,它的工作.. – Subindev