2015-06-10 136 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