我有一个文本框来引导用户输入要搜索的文本。
<TextBox Background="White"
Text="{Binding Path=Selected, UpdateSourceTrigger=PropertyChanged}"
TextChanged="textboxsearch_TextChanged"
Grid.Column="4" Margin="0,0,11,10" Height="22" Grid.ColumnSpan="2">
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Foreground" Value="{StaticResource SearchHint}"/>
</Trigger>
</Style.Triggers>
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
</TextBox.Style>
</TextBox>风格:
<VisualBrush x:Key="SearchHint" TileMode="None" Stretch="None" AlignmentX="Center">
<VisualBrush.Transform>
<TranslateTransform X="5" Y="0" />
</VisualBrush.Transform>
<VisualBrush.Visual>
<Grid>
<TextBlock FontStyle="Italic"
Foreground="Black"
Background="Black"
Text="Enter search text…" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>为什么Text="Enter search text…“运行程序时看不到吗?谢谢
发布于 2013-07-22 05:28:27
您不能将提示放在Foreground画笔中,因为那样只能绘制TextBox中的文本。请改用Background:
<TextBox Text="{Binding Path=Selected, UpdateSourceTrigger=PropertyChanged}"
TextChanged="textboxsearch_TextChanged"
Grid.Column="4" Margin="0,0,11,10" Height="22" Grid.ColumnSpan="2">
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Text" Value="">
<!-- here -->
<Setter Property="Background" Value="{StaticResource SearchHint}"/>
</Trigger>
</Style.Triggers>
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
</TextBox.Style>
</TextBox>然后使用这个笔刷:
<VisualBrush x:Key="SearchHint" TileMode="None" Stretch="None" AlignmentX="Center">
<VisualBrush.Transform>
<TranslateTransform X="5" Y="0" />
</VisualBrush.Transform>
<VisualBrush.Visual>
<Grid>
<TextBlock FontStyle="Italic" Text="Enter search text…"
Foreground="Black" Background="White"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>发布于 2013-07-20 03:34:33
看看它的风格:
<TextBlock FontStyle="Italic"
Foreground="Black"
Background="Black" Text="Enter search text…" />您的前景色和背景色是相同的。尝试将前景更改为白色?
https://stackoverflow.com/questions/17754037
复制相似问题