이라는 특정 WPF 스타일에 TargetType = "TextBlock"
이라는 문제가 있습니다. 스타일은 Foreground
, FontSize
및 Effect
을 정의합니다. 처음 TextBlock이 표시되면 전경 세터 만 실행되지 않고 (텍스트 색상은 검정으로 유지됨) FontSize 및 효과가 정상적으로 적용됩니다. 부모로부터 TextBlock을 제거하고 다시 돌려 주면 전경도 마찬가지로 변경됩니다..NET4 WPF - 컨트롤 숨기기/표시 후에 만 작동하는 포 그라운드 용 스타일 설정자
상황 :
Presenter.dll 어셈블리
- 클래스
Presenter: Window
, 부하 및 내 된 UserControls를 표시합니다. Generic.xaml
- 스타일이 포함 된 리소스 사전입니다.Presenter.dll
은 직접적으로TestPresentable.dll
을 참조하지 않습니다.
TestPresentable.dll 조립체
TestPresentable: UserControl
는 스타일TextBlock
있다.TestPresentable.dll
은 직접 참조하지 않습니다.Presenter.dll
.
MainApp.exe
-
모두 이전 어셈블리
- 참조
- 가
Presenter.dll
어셈블리MainWindow
인스턴스화 - 가
TestPresentable
어셈블리TestPresentable
인스턴스화 - 세트
MainWindow.ContentHost.Content = testPresentable
관련 코드 :
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}"/>
...