2011-09-27 41 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

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