2015-06-10 138 views
1

我是WPF的新手。我有一个约10000行的数据网格。为了实现搜索和突出的功能,下面的代码实现Wpf datagrid滚动条冻结

<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> 

搜索和亮点工作就像一个charm.But上垂直滚动整个电网冻结的点击。这可能是什么原因?

+0

我的猜测是,它运行每个行**转换器**。你可以给它一分钟来试验这个理论吗? –

+0

@MikeEason yes转换器必须通过每个单元才能实现搜索功能。 – subhasmita

回答

0

您可以使用Binding上的IsAsync属性。

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

这将强制您的绑定发生在另一个线程上,使您的UI免于冻结。但是,由于你有很多行,这可能需要一段时间,所以我建议也使用FallbackValue

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

这将在发生异步过程时提供值,典型值为文本,例如“加载...”消息。

+0

谢谢你的解决方案,但不幸的是它不工作。当我点击网格中的任何地方时,我观察到网格变为无响应状态。但是当网格加载时,在鼠标滚轮上移动的行就会滚动。 – subhasmita