Silverlight 通过相对资源绑定到父属性
我想不出哪里出了问题。 我希望将DropShadowEffect的颜色绑定到文本框的前景色。当我使用ElementName绑定属性进行绑定时,它可以正常工作,但我需要使用RelativeSource(在VisualThree中查找第一个TextBox对象) 下面是我的代码(Silverlight 5):Silverlight 通过相对资源绑定到父属性,silverlight,binding,Silverlight,Binding,我想不出哪里出了问题。 我希望将DropShadowEffect的颜色绑定到文本框的前景色。当我使用ElementName绑定属性进行绑定时,它可以正常工作,但我需要使用RelativeSource(在VisualThree中查找第一个TextBox对象) 下面是我的代码(Silverlight 5): U应该使用{RelativeSource self},因为您的effect属性依赖于TextBox(“TextBox1”),而不是TextBox父对象 <TextBox x:Name=
U应该使用{RelativeSource self},因为您的effect属性依赖于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>
Dima,我看到了你的照片。如果文本框的前景色设置为蓝色,那么如果绑定工作正常,阴影也应该是蓝色的。
<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>