Wpf datagrid scrollbar freezes

907 views Asked by At

I am new to WPF. I have a datagrid that has around 10000 rows. To implement search and highlight functionality,the following code is implemented

<Style x:Key="DefaultCell" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                        <ControlTemplate TargetType="DataGridCell">

                        <local:CustomTextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Content.Text}">
                            <!--InlineCollection="{Binding ., Converter={StaticResource StringToXamlConverter} }"/>-->
                            <local:CustomTextBlock.InlineCollection>
                              <MultiBinding Converter="{StaticResource StringToXamlConverter}">
                                    <Binding RelativeSource="{RelativeSource Self}" Path="." />
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(local:SearchOperations.SearchTerm)"/>
                                </MultiBinding>
                            </local:CustomTextBlock.InlineCollection>                                
                        </local:CustomTextBlock>                     
                    </ControlTemplate>
                </Setter.Value> 
            </Setter>   

The search and highlight is working like a charm.But on click of the vertical scrollbar entire grid freezes. What could be the reason here?

1

There are 1 answers

1
Mike Eason On

You can make use of the IsAsync property on your Binding.

<Binding RelativeSource="{RelativeSource Self}" Path="." IsAsync="True"/>

This will force your bindings to take place on a different thread, freeing up your UI from freezing. However, as you have lots of rows, this may take a while, so I would advise making use of FallbackValue too.

<Binding RelativeSource="{RelativeSource Self}" Path="." IsAsync="True" FallbackValue="..."/>

This will provide a value while the asynchronous process is taking place, a typical value would be text, such as a "Loading..." message.