0

何が悪いのかわかりません。DropShadowEffect の色を TextBox の前景色にバインドしたいと考えています。ElementName バインド プロパティを使用してバインドすると正常に動作しますが、RelativeSource を使用する必要があります (VisualThree で最初の TextBox オブジェクトを探します)。

以下は私のコードです(Silverlight 5です):

<Grid x:Name="LayoutRoot" Background="White">

<TextBox x:Name="TextBox1" Foreground="Blue" MinWidth="100" HorizontalAlignment="Center" VerticalAlignment="Center">
    <TextBox.Effect>
        <DropShadowEffect x:Name="ShadowEffect" BlurRadius="60" Direction="345" ShadowDepth="50" Color="{Binding Path=Foreground.Color, RelativeSource={RelativeSource AncestorType=TextBox}}"></DropShadowEffect>
    </TextBox.Effect>
</TextBox>

4

1 に答える 1

0

効果プロパティは TextBox の親ではなく TextBox("TextBox1") に依存しているため、{RelativeSource self} を使用する必要があります。

<TextBox x:Name="TextBox1" Foreground="Blue" MinWidth="100" HorizontalAlignment="Center" VerticalAlignment="Center"> 
<TextBox.Effect> 
    <DropShadowEffect x:Name="ShadowEffect" BlurRadius="60" Direction="345" ShadowDepth="50" Color="{Binding RelativeSource={RelativeSource self}, Path=Foreground.Color}"></DropShadowEffect> 
</TextBox.Effect> 

于 2012-04-18T06:22:25.877 に答える