views:

33

answers:

0

My generic.xaml code in the Assembly1:

 <Style x:Key="myLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="Red"/>
    <Setter Property="Content" Value="generic"/>
 </Style>

 <ControlTemplate x:Key="theButton" TargetType="{x:Type local:MyButton}">
    <Grid Background="Beige">
        <ContentPresenter/>
        <Label Style="{DynamicResource myLabelStyle}"/>
    </Grid>
</ControlTemplate>

<Style x:Key="{x:Type local:MyButton}" TargetType="{x:Type local:MyButton}">
    <Setter Property="Template" Value="{StaticResource theButton}"/>
</Style>

Assembly2 references Assembly1 and the used ResourceDicitonary contains following code:

<Style x:Key="myLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="Blue"/>
    <Setter Property="Content" Value="coool"/>
</Style>

If I execute the application all works fine. The label contains "coool" and its blue.

So for test purposes I commented out all the xaml definition listed above in the Assembly2. The idea is, to test if the generic.xaml is used as fallback.

It is used, but the label is empty and so it has no color. If I change in the generic.xaml from Style="{DynamicResource myLabelStyle}" to Style="{StaticResource myLabelStyle}"/>

 <ControlTemplate x:Key="theButton" TargetType="{x:Type local:MyButton}">
    <Grid Background="Beige">
        <ContentPresenter/>
        <Label Style="{StaticResource myLabelStyle}"/>
    </Grid>
 </ControlTemplate>

then is the label red and contains the content "generic". The problem is as soon as I use my style override in Assembly2. It has no effect. The label is still red and not blue as expected.

Both assemblies have the following assembly setting:

[assembly: ThemeInfo(
ResourceDictionaryLocation.SourceAssembly, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)

)]

Why wpf behaves that way, any idea?