我正试图在Background
中设置一个简单的TextBox
以及一些水印文本。我的代码基于Philip Patrick's blog的示例。WPF绑定风格
我试图调整它,以便在TextBox
上的ToolTip
属性中检索显示在背景中的文本。
目前这个工程:
<TextBox ToolTip="Type a name here...">
<TextBox.Background>
<VisualBrush TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left">
<VisualBrush.Visual>
<TextBlock FontStyle="Italic" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}, Path=ToolTip}"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Background>
</TextBox>
,显示在TextBox
的Background
的ToolTip
文本。
但是,如果我移动代码的一部分出来的资源风格的结合不再获得来自TextBox
的ToolTip
信息:
<Grid>
<Grid.Resources>
<Style x:Key="WatermarkBackground" TargetType="{x:Type TextBox}">
<Setter Property="Background">
<Setter.Value>
<VisualBrush TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left">
<VisualBrush.Visual>
<TextBlock FontStyle="Italic" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}, Path=ToolTip}"/>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<TextBox ToolTip="Type your name here..." Style="{StaticResource WatermarkBackground}"/>
这里
任何提示吗?
你能使用模板,而不是一个风格的,所以你可以使用{绑定的RelativeSource = {的RelativeSource TemplatedParent},路径=工具提示}? – 2010-03-30 16:57:24