我已经为文本框定义了样式,当文本框为空时,该样式将显示关于输入内容的提示。
这将是我的窗口:
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBox}" x:Key="stlHintbox">
<Style.Triggers>
<DataTrigger Binding="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" Value="">
<Setter Property="Background">
<Setter.Value>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<TextBlock Text="First name" FontStyle="Italic" Foreground="LightGray" />
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<TextBox Style="stlHintbox" />
</Grid>
抛出的错误是:
'Set property 'System.Windows.FrameworkElement.Style' threw an exception.' Line number '22' and line position '11'.
内部除外:
"'stlHintbox' is not a valid value for property 'Style'."
样式放置在内部时正常工作
<TextBox.Style>
,那我做错什么了?