2012-04-17 96 views
0

我無法弄清楚什麼是錯的。 我希望將DropShadowEffect的顏色綁定到TextBox Foreground顏色。當我使用ElementName綁定屬性進行綁定時,它工作正常,但我需要使用RelativeSource(在VisualThree中查找第一個TextBox對象)。通過RelativeSource綁定到Parent屬性

下面是我的代碼(它的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> 

預先感謝所有,

Saulo

回答

0

ü應該使用{的RelativeSource自},因爲你的效果屬性依賴於TextBox(「TextBox1」),而不是TextBox父項。

<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> 

+0

感謝您的關注,但它沒有工作! :'( – Saulo 2012-04-18 14:13:00

+0

https://skydrive.live.com/?cid=D1B83ACE5EB2C92A#cid=D1B83ACE5EB2C92A&id=D1B83ACE5EB2C92A%21167 – 2012-04-18 16:42:19

+0

Dima,我看到了你的圖像,如果文本框的前景顏色設置爲藍色,那麼陰影也應該是藍色的綁定工作正常。 – Saulo 2012-04-18 21:08:27

相關問題