WPF DataGrid滚动条冻结 [英] Wpf datagrid scrollbar freezes
问题描述
我是WPF的新手.我有一个大约10000行的数据网格.为了实现搜索和突出显示功能,实现了以下代码
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?
推荐答案
您可以在 Binding
上使用 IsAsync
属性.
<Binding RelativeSource="{RelativeSource Self}" Path="." IsAsync="True"/>
这将强制您的绑定发生在不同的线程上,从而使您的UI免于冻结.但是,由于您有很多行,这可能需要一段时间,所以我建议您也使用 FallbackValue
.
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.
这篇关于WPF DataGrid滚动条冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!