2011-09-27 95 views
0

我正在为我们不控制的棱柱应用程序编写模块。要求是在其中一个区域显示Web浏览器控件。不幸的是,每个窗口都来自一个CustomWindow类,它有AllowsTransparency=true。拥有AllowTransparency=true可防止显示WebBrowser控件。覆盖Prism模块中的WPF窗口样式

我可以右键单击并将鼠标悬停在控件上,并知道有一个网页加载(谷歌),所以我几乎可以肯定,我面临的问题与透明度和win32控件(其中的就我所知,WebBrowser是一个封装的win32控件)。

所以,我决定我唯一的做法是尝试重写窗口样式,关闭AllowTransparency。

这是违规的风格(使用反射浏览BAML):

<Style x:Key="{x:Type local:CustomWindow}" TargetType="{x:Type local:CustomWindow}"> 
    <Setter Property="AllowsTransparency" Value="true" /> 
    ... 
</Style> 

这就是我正在尝试删除样式:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Controls="clr-namespace:Vendor.App.WPFCommon.Controls;assembly=Vendor.App.WPFCommon"> 
    <Style TargetType="{x:Type Controls:CustomWindow}"> 
     <Setter Property="AllowsTransparency" Value="false" /> 
    </Style> 
</ResourceDictionary> 
private void LoadThemeOverrides() 
{ 
    var assemblyName = System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().ManifestModule.Name); 
    var overrides = new Uri(string.Format("{0};component/themes/overrides.xaml", assemblyName), UriKind.Relative); 
    var themeManager = _container.Resolve<IThemeManager>(); 
    foreach (var theme in themeManager.ThemeCollection) 
     theme.Sources.Add(overrides); 
    var rd = new ResourceDictionary {Source = overrides}; 
    Application.Current.Resources.MergedDictionaries.Add(rd); 
    themeManager.ChangeTheme(themeManager.CurrentTheme); 
} 

ResourceDictionary被正确加载,所以它不是问题的URI。我调试了rd,我可以在那里看到我的风格。

上面这段代码在验证用户/密码的登录窗口和正在显示的主应用程序窗口之间运行。它们是两个不同的窗口,但是它们都来自CustomWindow。

使用WPF Inspector,我可以看到CustomWindows仍然将AllowTransparency设置为true。我能否覆盖这种风格?或者我试图不正确地做到这一点?

回答

1

在windows中,设置隐式样式不适用于任何情况。你必须给出一个样式的关键,并找到一种方法来在需要的窗口上明确地设置样式。

根据您的架构,使用ResourceKey可能会有帮助。

+0

你能用“ResourceKey”来解释一下你的意思吗?我正在学习WPF,有很多google-foo。 –

+0

在您的覆盖字典中,而不是'