如何从UWP中的AutoSuggestBox中删除边框?

时间:2016-05-14 14:08:11

标签: xaml win-universal-app

我有AutoSuggestBox其边框我想删除。

<AutoSuggestBox x:Name="txtSearch" Width="200" QueryIcon="Find"
PlaceholderText="Search" Background="Transparent" BorderThickness="0" BorderBrush="Transparent" />

And yet I still get a border

1 个答案:

答案 0 :(得分:2)

创建了样式模板

<Style x:Key="AutoSuggestWithoutBorder" TargetType="AutoSuggestBox">
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="TextBoxStyle" Value="{StaticResource AutoSuggestBoxTextBoxStyle}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="AutoSuggestBox">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="Orientation">
                            <VisualState x:Name="Landscape"/>
                            <VisualState x:Name="Portrait"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <TextBox x:Name="TextBox"
                Style="{TemplateBinding TextBoxStyle}"
                PlaceholderText="{TemplateBinding PlaceholderText}"
                Header="{TemplateBinding Header}"
                Width="{TemplateBinding Width}"
                BorderThickness="0"
                ScrollViewer.BringIntoViewOnFocusChange="False"
                Canvas.ZIndex="0"
                Margin="0"
                DesiredCandidateWindowAlignment="BottomEdge"/>
                    <Popup x:Name="SuggestionsPopup">
                        <Border x:Name="SuggestionsContainer" BorderThickness="0">
                            <Border.RenderTransform>
                                <TranslateTransform x:Name="UpwardTransform"/>
                            </Border.RenderTransform>
                            <ListView
            x:Name="SuggestionsList"
            Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}"
            BorderThickness="0"
            BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
            DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
            IsItemClickEnabled="True"
            ItemTemplate="{TemplateBinding ItemTemplate}"
            ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
            ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
            MaxHeight="{ThemeResource AutoSuggestListMaxHeight}"
            Margin="{ThemeResource AutoSuggestListMargin}"
            Padding="{ThemeResource AutoSuggestListPadding}">
                                <ListView.ItemContainerTransitions>
                                    <TransitionCollection />
                                </ListView.ItemContainerTransitions>
                            </ListView>
                        </Border>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

在需要的地方使BorderThickness为0。