c# – 如何使用wpf中的清除按钮实现文本框?

前端之家收集整理的这篇文章主要介绍了c# – 如何使用wpf中的清除按钮实现文本框?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下的UserControl.它是一个带有按钮的TextBox
  1. <Grid>
  2. <TextBox
  3. Grid.Column="0"
  4. Text="{Binding Text,RelativeSource={RelativeSource AncestorType=UserControl},UpdateSourceTrigger=PropertyChanged}"
  5. x:Name="TextBox" />
  6.  
  7. <Button
  8. Background="{Binding Background,ElementName=TextBox}"
  9. Grid.Column="1"
  10. Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
  11. HorizontalAlignment="Right"
  12. Visibility="{Binding IsClearButtonVisible,Converter={StaticResource BooleanToVisibilityConverter}}"
  13. Command="{Binding ClearTextCommand,RelativeSource={RelativeSource AncestorType=UserControl}}"
  14. HorizontalContentAlignment="Center"
  15. VerticalContentAlignment="Center" >
  16.  
  17. <Button.Content>
  18. <Image
  19. Source="{StaticResource Delete2}"
  20. Stretch="None"
  21. RenderOptions.BitmapScalingMode="NearestNeighbor"
  22. VerticalAlignment="Center"
  23. HorizontalAlignment="Center" />
  24. </Button.Content>
  25. </Button>
  26. </Grid>

在Windows 7中看起来不错,但在Windows XP中我有以下问题:

关于如何解决这个问题的任何想法?如果我使背景透明,那么按钮没有问题,但文本在按钮下方看起来很奇怪.

解决方法

使按钮更小和/或添加一个小边距以“缩小”可视背景.

编辑:周围看一点(想知道这没有被添加为一些新功能)我发现了this article with step-by-step instructions you could give a try.

猜你在找的C#相关文章