12

我有以下UserControl。它是TextBox一个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 中我有以下问题:

在此处输入图像描述

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

4

3 回答 3

6

缩小Button和/或添加小边距以“缩小”可见背景。

编辑:虽然环顾四周(想知道这还没有被添加为一些新功能),我发现这篇文章有分步说明,你可以试一试

于 2012-11-29T11:24:28.330 回答
6

试试这个。

<TextBox x:Name="SearchFilter" VerticalAlignment="Center" Width="200"  
                                 Text="{Binding SearchItemString}" />
<Button Margin="-20,10,5,0" Width="25" Height="25" Content="X" 
                        Style="{StaticResource TransparentStyle}" />

这里是风格。

<Style x:Key="TransparentStyle" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="Transparent">
                    <ContentPresenter/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

结果:

于 2018-11-06T10:38:25.873 回答
3

我认为你应该ControlTemplate在这里使用 s,例如你可以看到搜索文本框控件在这里你可以找到文本框模板

于 2012-11-29T12:53:10.220 回答