2016-03-22 4 views
1

ViewModelのプロパティの1つをDropShadowEffectのカラーにバインドしたいとします。何千ものバリエーションのように試しましたが、どれも動作していないようです。DropShadowEffectカラーバインディングが機能しない

スタイル:

<Style TargetType="{x:Type Image}" x:Key="CentralImageStyle"> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Effect"> 
       <Setter.Value> 
        <DropShadowEffect ShadowDepth="0" 
        Color="{Binding Path=DataContext.CurrentPlayer.Character, Converter={StaticResource CharacterColorConverter}, 
         RelativeSource={RelativeSource AncestorType={x:Type Window}}}" 
        Opacity="1" BlurRadius="50"/> 
       </Setter.Value> 
      </Setter> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

コントロール:

<Image Source="{Binding CurrentPlayer.BackImageSource}" 
     Style="{DynamicResource ResourceKey=CentralImageStyle}"> 

およびコンバータ:

switch ((string)value) 
{ 
    case "char1": 
     return new SolidColorBrush(Colors.WhiteSmoke); 
    case "char2": 
     return new SolidColorBrush(Colors.Red); 
    default: 
     return new SolidColorBrush(Colors.White); 
} 

私の問題はDropShadowEffectの色が黒であるということです。これはコンバータが使用されていないことを意味します。

答えて

1

あなたはColorプロパティにバインドしていますが、コンバータはBrushesを返しています。コンバータからSolidColorBrushを削除し、Colors.WhiteSmoke、Colors.Redなどを返します。

+0

ありがとう、それは私の問題を解決しました。 –