Question

I had an strange Bug in my application. Whenever the AboutDialog would be displayed the companylogo on the mainwindow vanished.

I have the discovered that this is related to multiple windows using the same resource simultaneous. In my testapplication I am starting two windows like this:

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

On my Mainwindow I am using a ContentPresenter with a path stored as Application resource. This does not happen with a string. But my logo is only displayed on one Window.

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

Does anyone have an idea how to fix this?

Edit:

In my real-world-application my logo is stored in a ResourceDictionary so it is not possible to set x:Shared to false.

Was it helpful?

Solution

Set x:Shared = false on the Canvas resource to return the new instance everytime.

   <Canvas x:Key="BrandingLogo" x:Shared = "false"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top