【问题标题】:Opacity is not getting applied to the WPF Popup control不透明度未应用于 WPF Popup 控件
【发布时间】: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;

怎么做?

【问题讨论】:

    标签: c# wpf popup opacity


    【解决方案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
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-19
      • 2023-02-26
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2011-03-18
      • 2011-02-08
      相关资源
      最近更新 更多