views:

12

answers:

1

Hi.

I work on a WPF project with many UserControls and I'm trying to put some sanity in my WPF resources.

A base file contains generic stuff needed by all views, such as colors:

<!-- Resources.xaml -->
<Color x:Key="FlashOrange">#F59500</Color>

Then, a resource file specific to a view needs to reference FlashOrange:

<!-- ContactViewResources.xaml -->
<DataTrigger Binding="{Binding IsActiveConversation}" Value="True">
    <Setter Property="Background" Value="{StaticResource FlashOrange}"/>
</DataTrigger>

Finally I'd like to "include" both in my UserControl. Unfortunately, with this approach I get an exception about {StaticResource FalshOrange} not being defined.

<!-- ContactView.xaml -->
<UserControl.Resources>        
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="..\Resources.xaml"/>
            <ResourceDictionary Source="ContactViewResources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>     
</UserControl.Resources>

All the view files are in the same DLL assembly, and a separate EXE assembly runs

Thanks!

A: 

Either merge Resources.xaml into ContactViewResources.xaml, so the Static reference has a direct path to FlashOrange in its resource tree at load time, or use DynamicResource instead.

John Bowen