3

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?

Spider man
  • 3,224
  • 4
  • 30
  • 42
subhasmita
  • 31
  • 2

1 Answers1

0

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.

Mike Eason
  • 9,525
  • 2
  • 38
  • 63
  • thank you for the solution but unfortunately it is not working. What I have observed when I click anywhere in the grid the grid goes to not responding state. But when the grid is loaded,on mouse scroll wheel move the rows are scrolling. – subhasmita Jun 10 '15 at 09:21