从搜索栏中删除搜索图标:Winrt

时间:2014-07-10 07:10:52

标签: c# windows-store-apps winrt-xaml windows-8.1

Windows 8.1中的搜索栏附有默认搜索图标。

喜欢这个

enter image description here

有什么方法可以摆脱那个图标吗?

1 个答案:

答案 0 :(得分:2)

您需要编辑SearchBox的样式以删除搜索按钮。

要获得SearchBox的风格,请按照以下步骤

第1步:http://i.imgur.com/tg8icLv.png

第2步:http://i.imgur.com/VdB28oY.png并按确定

第3步:http://i.imgur.com/9wNmQga.png

 <Style x:Key="SearchBoxStyle1" TargetType="SearchBox">
        ..........................
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="SearchBox">
                    ......
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="SearchTextBox" BorderThickness="0" Background="Transparent" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" InputScope="Search" MinHeight="{ThemeResource SearchBoxTextBoxThemeMinHeight}" MaxLength="2048" Padding="{TemplateBinding Padding}" PlaceholderText="{TemplateBinding PlaceholderText}" Style="{StaticResource SearchTextBoxStyle}" TextWrapping="NoWrap" VerticalAlignment="Stretch"/>
                    <Button x:Name="SearchButton" Height="0" Width="0" AutomationProperties.AccessibilityView="Raw" Background="Transparent" Grid.Column="1" FontWeight="{ThemeResource SearchBoxButtonThemeFontWeight}" Style="{StaticResource SearchButtonStyle}"/>
                    .......
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<SearchBox Height="35" Width="200" Style="{StaticResource SearchBoxStyle1}"/>