WPF透明用户控件背景

时间:2015-11-03 05:00:36

标签: c# wpf user-controls

好吧,我多次看到这个问题,但是给TS的所有答案都不适用于我的UserControl。 =(

问题是,当我在Designer内的UserControl上使用Background属性时,它只有在我将其设置为真实颜色时才有效,如红色,蓝色,绿色等。

然而,当我尝试将其设置为透明时,它再次变为白色。

我有一个看起来像这样的窗口 enter image description here

我想要实现的是这个 enter image description here

但是我得到的就是这个(这个白色的背景,或者除了透明之外的任何颜色) enter image description here

有关如何使其成为可能的任何建议吗?

P.S。此自定义用户控件是一种MessageBox

更新!忘了提这个控件的源代码 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();  
    }
}

1 个答案:

答案 0 :(得分:1)

在Window上添加一个Loaded事件并在那里调用TimedCall()。您的窗口尚未加载,这就是您想要的背景尚未生效的原因。

相关问题