Xaml 如何实现搜索提示的VisualBrush

Xaml 如何实现搜索提示的VisualBrush,xaml,Xaml,我有一个文本框,引导用户输入搜索文本 <TextBox Background="White" Text="{Binding Path=Selected, UpdateSourceTrigger=PropertyChanged}" TextChanged="textboxsearch_TextChanged" Grid.Column="4" Margin="0,0,11,10" Height

我有一个文本框,引导用户输入搜索文本

<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>

为什么在运行程序时,文本=“输入搜索文本…”不可见? 谢谢

看看款式:

 <TextBlock FontStyle="Italic"
            Foreground="Black"  
            Background="Black" Text="Enter search text…" />


您的前景色和背景色相同。尝试将前景更改为白色?

您不能将提示放在
前景
画笔中,因为这样只会在文本框中绘制文本。使用
背景

<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>