半透明自定义布局面板
我通过将面板的不透明度值设置为 0.5,在 WPF 中构建了一个半透明自定义布局面板。一切都按预期工作,除了面板的子项也是半透明的!
我需要更改什么才能使面板的子项呈现不透明?
以下是相关代码:
public class DialogLayoutPanelControl : Panel
{
public DialogLayoutPanelControl() : base()
{
Background = Brushes.LightGray;
Opacity = 0.5;
}
}
解决方案(由 Anvaka 提供):
Background = new SolidColorBrush(Colors.LightGray) { Opacity = 0.5 };
I have built a semi-transparent custom layout panel in WPF by setting the Opacity value of the panel to 0.5. Everything works as expected, except that the children of the panel are also semi-transparent!
What do I need to change to have the children of the panel rendered without transparency?
Here's the relevant code:
public class DialogLayoutPanelControl : Panel
{
public DialogLayoutPanelControl() : base()
{
Background = Brushes.LightGray;
Opacity = 0.5;
}
}
Solution (by Anvaka):
Background = new SolidColorBrush(Colors.LightGray) { Opacity = 0.5 };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常感谢Anvaka,你也帮助了我。就我而言,我是通过 XAML(来自样式)完成的:
Thank you very much Anvaka, you helped me also. In my case, I did it from XAML (from style):
改变画笔的不透明度,而不是控制它自己......
Change the opacity of the brush, rather than control itself...