半透明的自定义布局面板 [英] Semi-transparent custom layout panel

查看:77
本文介绍了半透明的自定义布局面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过将面板的不透明度"值设置为0.5,在WPF中构建了一个半透明的自定义布局面板.一切都按预期工作,除了面板的子代也是半透明的

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?

以下是相关代码:

public class DialogLayoutPanelControl : Panel
{
    public DialogLayoutPanelControl() : base()
    {
        Background = Brushes.LightGray;
        Opacity = 0.5;
    }
 }

解决方案(由Anvaka撰写):

Solution (by Anvaka):

    Background = new SolidColorBrush(Colors.LightGray) { Opacity = 0.5 };

推荐答案

更改画笔的不透明度,而不是控制自身...

Change the opacity of the brush, rather than control itself...

这篇关于半透明的自定义布局面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆