开发者

Silverlight AutoCompleteBox takes a long time to respond on first "search"

开发者 https://www.devze.com 2022-12-09 13:17 出处:网络
I have a Silverlight application which loads about 2000 objects of half a dozen fields into an AutoCompleteBox.The filter is then set to search on any of four of the fields.I\'ve set it to begin searc

I have a Silverlight application which loads about 2000 objects of half a dozen fields into an AutoCompleteBox. The filter is then set to search on any of four of the fields. I've set it to begin searching after two characters.

However, when I type the second character (when the box is supposed to start populating) for the very first time after populating the List of objects, the AutoCompleteBox takes about 6-7 seconds to respond.

Any ideas on how I can optimize this?

Is there a way to create these visual elements right after the list is populated instead of waiting for the user to begin typing?开发者_运维知识库


Have you alreay adjusted the MinimumPrefixLength propery? The more characters you require, the filtering will be better.

Right now, with a low prefix, you have 2000+ visual elements that are created, minus say one character of filtering, regardless of any other optimizations.

Another option is to implement your own background thread-filtering, but that defeats many of the purposes for the control (i.e. simplicity).


It is bug in AutoCompleteBox control.

When DropDown is opened for the first time, UI Virtualization is not used and control creates all items.

To fix this you must set MaxHeight to Grid of dropdown Popup in AutoCompleteBox ControlTemplate. This is XAML part of this ControlTemplate:

<ControlTemplate TargetType="sdk:AutoCompleteBox">
    <Grid Opacity="{TemplateBinding Opacity}">
        ...

        <Popup x:Name="Popup">
            <Grid Opacity="{TemplateBinding Opacity}" MaxHeight="450">
                <Border x:Name="PopupBorder" BorderThickness="0" Background="#11000000" HorizontalAlignment="Stretch" Opacity="0">
                    <Border.RenderTransform>
                        <TranslateTransform X="1" Y="1"/>
                    </Border.RenderTransform>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" HorizontalAlignment="Stretch" Opacity="1.0" Padding="0">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFDDDDDD" Offset="0"/>
                                <GradientStop Color="#AADDDDDD" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <Border.RenderTransform>
                            <TransformGroup>
                                <TranslateTransform X="-1" Y="-1"/>
                            </TransformGroup>
                        </Border.RenderTransform>
                        <ListBox x:Name="Selector" BorderThickness="0" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemTemplate="{TemplateBinding ItemTemplate}" ItemContainerStyle="{TemplateBinding ItemContainerStyle}" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
                    </Border>
                </Border>
            </Grid>
        </Popup>
    </Grid>
</ControlTemplate>

This works for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消