2013-09-30 47 views
0

我的應用程序中有一個奇怪的錯誤。每當AboutDialog顯示時,主窗口上的companylogo消失。多個WPF Windows使用相同的資源同時

我發現這與使用相同資源的多個窗口同時相關。 在我testapplication我開始兩個窗口是這樣的:

void App_Startup(object sender, StartupEventArgs e) 
{ 
    MainWindow mainWindow = new MainWindow(); 
    mainWindow.Top = 100; 
    mainWindow.Left = 900; 
    mainWindow.Show(); 
} 

在我的主窗口,我使用存儲爲應用程序資源路徑的ContentPresenter。這不會發生在字符串中。但我的標誌只顯示在一個窗口上。

<StackPanel> 
     <ContentPresenter x:Name="Logo" Content="{DynamicResource BrandingLogo}" Margin="20" HorizontalAlignment="Center"/> 
     <TextBox Text="{DynamicResource MyConstString}"/> 
    </StackPanel> 

有沒有人有一個想法如何解決這個問題?

編輯:

在我的現實世界的應用程序我的標誌存儲在ResourceDictionary中,因此無法設置X:共享爲false。

回答

1

Canvas資源上設置x:Shared = false以每次都返回新實例。

<Canvas x:Key="BrandingLogo" x:Shared = "false"/> 
+0

這是非常好的,如果我的資源不會位於ResourceDictionary將工作。 -.- http://connect.microsoft.com/VisualStudio/feedback/details/776631/using-x-shared-in-a-resourcedictionary-prevents-you-from-setting-the-file-build-action -to-資源 – Kingpin

+0

它應該工作...你嘗試過嗎? – Nitin

+0

是的,我會試圖加載我的資源字典時,以下情況例外。 XamlParseException: 命名空間'http://schemas.microsoft.com/winfx/2006/xaml'中的共享屬性只能在已編譯的資源字典中使用。 – Kingpin

相關問題