简体   繁体   English

WPF透明用户控件背景

[英]WPF Transparent UserControl Background

Well, i saw this question so many times, but all the answers given to TS are not applicable to my UserControl. 好吧,我看过这个问题很多次了,但是给TS的所有答案都不适用于我的UserControl。 =( =(

The problem is, when i use Background property on UserControl inside Designer, it works only if i set it to real color, like Red, Blue, Green, etc. 问题是,当我在Designer内的UserControl上使用Background属性时,仅当我将其设置为真实颜色(如红色,蓝色,绿色等)时,它才起作用。

However, when i try to set it to Transparent, it again becomes white. 但是,当我尝试将其设置为“透明”时,它再次变为白色。

I have a window which looks like this 我有一个像这样的窗户
在此处输入图片说明

What im trying to achieve, is this 我试图达到的目标是
在此处输入图片说明

But all im getting is this (this whiteish background, or really any color except transparent) 但是我得到的只是这个(白色背景,或者实际上除了透明以外的任何颜色) 在此处输入图片说明

Any suggestions on how to make it possible? 关于如何使其成为可能的任何建议?

PS This custom user control is a kind of a MessageBox PS此自定义用户控件是一种MessageBox

Update! 更新! Forgot to mention source code for this control http://www.codeproject.com/Tips/563144/WPF-Dialog-MessageBox-Manager (by Ronald Schlenker ) 忘记提及此控件的源代码 http://www.codeproject.com/Tips/563144/WPF-Dialog-MessageBox-Manager (作者Ronald Schlenker

public partial class LoginWindow : Window
{
    public LoginWindow()
    {
        InitializeComponent();
        string languageCode = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
        string Path = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
        TimedCall();
    }

    private void TimedCall()
    {
        System.Threading.Timer timer = null;
        timer = new System.Threading.Timer((obj) =>
        {
            ShowMessageBox();
            timer.Dispose();
        },
                    null, 3000, System.Threading.Timeout.Infinite);
    }

    private void ShowMessageBox()
    {
        var _dialogManager = new DialogManager(this, Dispatcher);
        _dialogManager
        .CreateMessageDialog("Test", "I'm a dialogafsaffsfsf", DialogMode.Ok)
        .Show();  
    }
}

Add a Loaded event on your Window and call TimedCall() there. 在您的窗口上添加一个Loaded事件,然后在其中调用TimedCall()。 Your window is not loaded yet, that is why the background you desire is not taking in effect yet. 您的窗口尚未加载,这就是您希望的背景尚未生效的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM