0

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.

1 Answer 1

1

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

   <Canvas x:Key="BrandingLogo" x:Shared = "false"/>
Sign up to request clarification or add additional context in comments.

5 Comments

This is very good and would work if my Resource would not be located in a ResourceDictionary. -.- connect.microsoft.com/VisualStudio/feedback/details/776631/…
Yes, i will get following exception when trying to load my ResourceDictionary. XamlParseException: Shared attribute in namespace 'schemas.microsoft.com/winfx/2006/xaml' can be used only in compiled resource dictionaries.
what is the buildaction of your dictionary?
buildaction is Resource
as the workaround stated.. can you try changing it to Page and try again with x:Shared

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.