I have a problem with a certain WPF style called HeadText
with TargetType = "TextBlock"
. The style defines Foreground
, FontSize
and Effect
. The first time a TextBlock is shown only the Foreground setter is not fired (text color stays black), FontSize and Effect are applied normally. When I remove the TextBlock from parent and return it back, then the foreground is also changed as it should.
Situation:
Presenter.dll assembly
- class
Presenter: Window
, loads and displays my usercontrols. Generic.xaml
- Resource dictionary that contains styles.Presenter.dll
does not directly referenceTestPresentable.dll
.
TestPresentable.dll assembly
TestPresentable: UserControl
, has a styledTextBlock
.TestPresentable.dll
does not directly referencePresenter.dll
.
MainApp.exe
- references both previous assemblies,
- instantiates
MainWindow
fromPresenter.dll
assembly, - instantiates
TestPresentable
fromTestPresentable
assembly, - sets
MainWindow.ContentHost.Content = testPresentable
Relevant code:
Presenter.dll
// Themes/Generic.xaml
...
<Style TargetType="{x:Type TextBlock}" x:Key="HeadText">
<Setter Property="Foreground" Value="#FFFFFFFF" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="#79000000" BlurRadius="3" Opacity="1" />
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="24"/>
</Style>
...
// MainWindow.xaml
...
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Presenter.dll;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ContentPresenter Name="ContentHost"/>
</Grid>
...
TestPresentable.dll
// TestPresentable.xaml
...
<TextBlock Text="{Binding SomeData}" Style="{DynamicResource HeadText}"/>
...