Tuesday, May 22, 2012

WPF Scroll Viewer slow performance (Bind control height from another object using code)

In this post, I created a datagrid dynamically or from code. When a record is loaded, the scrolling is slow using Scrollviewer control. So to translate into code behind here's what i come up..
Code:
Binding bindHeight = new Binding();  
bindHeight.ElementName = String.Format("sizingElement{0}", index + 1);  
bindHeight.FallbackValue = 1;  
bindHeight.Path = new PropertyPath("ActualHeight");  
//mapGrid is the datagrid object  
mapGrid.SetBinding(DataGrid.HeightProperty, bindHeight); 
XAML Markup:
 <StackPanel x:Name="spThur" Height="Auto" Background="Green" HorizontalAlignment="Left" Orientation="Horizontal">  
      <Rectangle Name="sizingElement4" Fill="Transparent" Margin="1" Height="333"/>  
  </StackPanel>  
The mapGrid datagrid is added to the stackpanel. And the Rectangle object is the sizing element.I found the solution from this site:
http://stackoverflow.com/questions/7254362/scrollviewer-slow-perfomance-with-datagrid

0 comments:

Post a Comment