Background
에 워터 마크 텍스트가있는 간단한 TextBox
을 함께 설정하려고합니다. 내 코드는 Philip Patrick's blog의 예제를 기반으로합니다.WPF 스타일로 바인딩
배경에 표시된 텍스트가 TextBox
의 ToolTip
속성에서 검색되도록 조정하려고합니다.
현재이 작품 다음 TextBox
의 Background
에서 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
에서 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}"/>
모든 팁을 여기를?
당신이 스타일 대신 템플릿을 사용할 수 제레미 여기에 구체적으로 무엇입니까? –