2009-08-14 22 views
14

XAMLの構文で少し苦労しています。誰かが助言してくれることを祈っています。私はいつも手動でプロパティを設定するのではなく、再利用できるDropShadowEffect定義を含む "Effect"タイプのスタイルリソースを作成したいと思います。ここに私が持っているものは次のとおりです:XAMLでドロップシャドウスタイルを作成する

<Style TargetType="DropShadowEffect" x:Name="DropShadowEffectStyle"> 
    <Setter Property="BlurRadius" Value="5" /> 
    <Setter Property="Direction" Value="315" /> 
    <Setter Property="ShadowDepth" Value="2" /> 
    <Setter Property="Opacity" Value="0.5" /> 
</Style> 

<Style TargetType="TextBlock" x:Name="PageTabLabelStyle"> 
    <Setter Property="FontSize" Value="16" /> 
    <Setter Property="FontFamily" Value="Arial" /> 
    <Setter Property="Foreground" Value="#EFEFEF" /> 
    <Setter Property="VerticalAlignment" Value="Center" /> 
    <Setter Property="Margin" Value="0, 10, 0, 10" /> 
    <Setter Property="Effect" Value="{StaticResource DropShadowEffectStyle}" /> 
</Style> 

これは私が明らかに何かが欠けているので、これはdismally失敗するたびに失敗します。私は、 "DopShadowEffect"タイプではなく "Effect"タイプを期待するテキストブロックスタイルの "Effect"プロパティの周りにあると思います。何か案は?

答えて

28

スタイルはコントロールのプロパティで、エフェクトはコントロールではないので、エフェクトをスタイルすることはできません。

本当にやりたかったのは、エフェクト自体をリソースディクショナリに入れ、それを指すStaticResource参照を使用することです。次のようなもの:

<UserControl.Resources> 
    <DropShadowEffect x:Key="dropShadow" BlurRadius="25" Direction="315" /> 
    <Style TargetType="TextBlock" x:Name="PageTabLabelStyle"> 
     <Setter Property="FontSize" Value="16" /> 
     <Setter Property="FontFamily" Value="Arial" /> 
     <Setter Property="Foreground" Value="#EFEFEF" /> 
     <Setter Property="VerticalAlignment" Value="Center" /> 
     <Setter Property="Margin" Value="0, 10, 0, 10" /> 
     <Setter Property="Effect" Value="{StaticResource dropShadow}" /> 
    </Style> 
</UserControl.Resources> 
+0

パーフェクト、thanks Keith。 DropShadowEffect宣言に言及する価値があるのは、参照される前に現れなければならない(おそらく直ちに明らかではない場合もある)。 –

+0

私はそれを行う別の方法を見つけた[ここ](http://stackoverflow.com/a/5157480/3029422) – Ionut

関連する問題