提示文本框样式问题 [英] Hint textbox style problem

查看:90
本文介绍了提示文本框样式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All。

我正在尝试为文本框创建一个样式,使文本框像一个提示框,但我希望这个样式可以动态重用于许多文本框,并且每次我都可以改变提示我确实创造了这种风格





我应该写什么代替....... 在标签内容绑定中是否在文本框标签中有界?



我尝试过:



Hello All.
I am trying to make a style for a textbox witch make the textbox like a hintbox, but i want the style to be dynamic reusable for many textbox and in every time i can change the hint to i did create this style


the question what should i write in place of " ....... " in the label content binding to be bounded in the textbox tag?

What I have tried:

<Style.Resources>
                <VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
                    <VisualBrush.Visual>
                        <Label Content="{Binding  .......}" Foreground="LightGray" Opacity="0.5" />
                    </visualbrush.Visual>
                </visualbrush>
            </style.Resources>
            <Style.Triggers>
                <Trigger Property="Text" Value="{x:Static sys:String.Empty}">
                    <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
                </trigger>
                <Trigger Property="Text" Value="{x:Null}">
                    <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
                </trigger>
                <Trigger Property="IsKeyboardFocused" Value="True">
                    <Setter Property="Background" Value="White" />
                </trigger>
            </style.Triggers>

推荐答案

您可以将文本框中的Tag元素设置为适用的提示文本,并绑定到Tag元素。然而,人们不禁要问,为什么你不只是使用ToolTip来做那种事情......



BTW,我也假设你的风格是 TargetType 设置为 TextBox



你的绑定会看起来像这样:

You could set the Tag element on the textbox to the applicable hint text, and bind to the Tag element. However, one has to wonder why you're not just using the ToolTip for that kind of thing...

BTW, I'm also assuming that your style's TargetType is set to TextBox.

Your binding would look like this:
{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag}" 


这篇关于提示文本框样式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆