WPF用户控件背景透明度不为';行不通
我尝试使用自己的类ModalDialogManager:Control弹出一个usercontrol,但是背景看起来不透明,如图所示 在我的ModalDialogManager类中,我确实指定了允许透明度的窗口:WPF用户控件背景透明度不为';行不通,wpf,user-controls,transparency,Wpf,User Controls,Transparency,我尝试使用自己的类ModalDialogManager:Control弹出一个usercontrol,但是背景看起来不透明,如图所示 在我的ModalDialogManager类中,我确实指定了允许透明度的窗口: Window w = new Window(); m_window = w; w.Closing += w_Closing; w.Owner = GetParentWindow(this); w.DataC
Window w = new Window();
m_window = w;
w.Closing += w_Closing;
w.Owner = GetParentWindow(this);
w.DataContext = this.DataContext;
w.SetBinding(Window.ContentProperty, "");
w.Title = Title;
w.Icon = Icon;
w.Height = DialogHeight;
w.Width = DialogWidth;
w.ResizeMode = DialogResizeMode;
// SHOULD IT WORK?!
w.AllowsTransparency = true;
double t = GetParentWindow(this).Left;
if (IsBorderless)
{
w.WindowStyle = WindowStyle.None;
w.ShowInTaskbar = false;
if (IsStartUpLocationCenter)
{
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
else
{
w.Left = LeftPosition;
w.Top = RightPosition;
w.WindowStartupLocation = WindowStartupLocation.Manual;
}
}
else
{
w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
if (IsModal)
w.ShowDialog();
else
w.Show();
但UserControl设计显示ok:
因此,我尝试使用窗口附加usercontrol,并使用usercontrol执行window.showDialog(),如下所示:
Window w = new Window();
SolidColorBrush b = new SolidColorBrush();
b.Color = .Colors.Transparent;
w.Background = b;
Grid g = new Grid();
g.Children.Add(new ucSelectCloth());
w.Content = g;
g.Background = b;
w.Height = 300;
w.Width = 600;
w.ShowDialog();
正如您所看到的,窗口看起来也不透明
有什么想法吗?窗口将保持不透明,直到您将属性设置为true。将
Window.allowTransparency
设置为true
后,必须将WindowStyle设置为None
在代码中添加以下行:
w.WindowStyle = System.Windows.WindowStyle.None;
w.AllowsTransparency = true;
嗨,查图,很抱歉代码不完整。窗口版本工作得很好,只是包含用户控件的类不工作。我可以知道为什么吗?