如何实现与WPF中的清除按钮文本框? [英] How to implement a textbox with a clear button in wpf?
问题描述
我有如下的用户控件
。这是一个文本框
与按钮
:
I have the following UserControl
. It's a TextBox
with a Button
:
<Grid>
<TextBox
Grid.Column="0"
Text="{Binding Text,
RelativeSource={RelativeSource AncestorType=UserControl},
UpdateSourceTrigger=PropertyChanged}"
x:Name="TextBox" />
<Button
Background="{Binding Background, ElementName=TextBox}"
Grid.Column="1"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
HorizontalAlignment="Right"
Visibility="{Binding IsClearButtonVisible,
RelativeSource={RelativeSource AncestorType=UserControl},
Converter={StaticResource BooleanToVisibilityConverter}}"
Command="{Binding ClearTextCommand,
RelativeSource={RelativeSource AncestorType=UserControl}}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" >
<Button.Content>
<Image
Source="{StaticResource Delete2}"
Stretch="None"
RenderOptions.BitmapScalingMode="NearestNeighbor"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button.Content>
</Button>
</Grid>
在Windows 7中,它看起来不错,但在Windows XP中,我有以下问题:
In Windows 7 it looks great but in Windows XP I have the following issue:
如何解决该问题的任何想法?如果我让背景透明再有就是与按钮没有问题,但文得到下面的按钮,看起来怪怪的。
Any ideas on how to fix the issue? If I make the background transparent then there is no problem with the button but the text gets below the button and looks weird.
推荐答案
,使按钮
更小和/或添加一个小幅度的,以缩小可见背景
Make the Button
smaller and/or add a small margin to "downsize" the visible background.
编辑:虽然环视了一下(不知道这个尚未添加一些新的功能),我发现的这篇文章一步一步的指导,你可以给一个尝试。
While looking around a bit (wondering that this hasn't been added as some new Feature) I've found this article with step-by-step instructions you could give a try.
这篇关于如何实现与WPF中的清除按钮文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!