Search code examples
wpfresourcedictionary

WPF share resourcedictionaries among controls


I have 2 dictionaries merged in my WPF app (base dict merged with skin dict). It works very fine on the MainWindow, but when I added a new WPF Window, it seems unable to access the StaticResource.

This is the code of the new Window:

<Window x:Class="Sc2ReplayMonkey.PleaseWaitWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:local="clr-namespace:Sc2ReplayMonkey"
        Title="PleaseWaitWindow" Height="300" Width="300">
    <Grid Style="{StaticResource WindowBackground}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Style="{StaticResource WindowTextelement}" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">
            Please wait while the replays            
        </TextBlock>
        <TextBlock Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
            are parsed and serialized
        </TextBlock>
    </Grid>
</Window>

I get the error "Cannot find the resource named "WindowBackground". It is defined in the skin dict as:

<Style x:Key="WindowBackground" TargetType="{x:Type Grid}">
    <Setter Property="Background" Value="Black" />
</Style>

What did I miss?


Solution

  • This solved the problem, I simply added a line in PleaseWaitWindow's constructor: Resources = main.Resources; main being the MainWindow