首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现搜索提示的VisualBrush

如何实现搜索提示的VisualBrush
EN

Stack Overflow用户
提问于 2013-07-20 03:29:19
回答 2查看 111关注 0票数 1

我有一个文本框来引导用户输入要搜索的文本。

代码语言:javascript
复制
<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>

风格:

代码语言:javascript
复制
<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…“运行程序时看不到吗?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-22 05:28:27

您不能将提示放在Foreground画笔中,因为那样只能绘制TextBox中的文本。请改用Background

代码语言:javascript
复制
<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>

然后使用这个笔刷:

代码语言:javascript
复制
<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>
票数 0
EN

Stack Overflow用户

发布于 2013-07-20 03:34:33

看看它的风格:

代码语言:javascript
复制
 <TextBlock FontStyle="Italic"
            Foreground="Black"  
            Background="Black" Text="Enter search text…" />

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17754037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档