I have two DataGrid
s and i have synchronous scrolling in place (scrolling on one grid causes other to scroll). One of the grids has a DataGridTemplateColumn
with DataTemplate
set to an Image
:
<DataGridTemplateColumn Width="16">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="CommentIcon_Clicked" />
</Style>
</DataGridTemplateColumn.CellStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Blank, Mode=TwoWay}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
After data is bound to the grids, scrolling becomes very sluggish and slow. Therefore i suspect its the Source
property binding operation that causes the sluggishness everytime scrolling occurs because if i set the binding to a StaticResource
, then the scrolling becomes smooth. Is there a way to fix this?
Update
The problem is because of the binding errors to the Image
source. The value of the property that binds to the Image
source is an empty string:
var d2 = (from l in t.Item2
select new ProgramLine { Blank = String.Emtpty, Line = l}).ToList();
dataGrid2.ItemsSource = d2;
This was causing the default converter to fail and hence cause the scrolling to become sluggish because of the property getter getting called everytime the scrolling occurred.
Lesson learnt Like Steven says, make sure there are no binding errors
Tip Use the immediate window when running your WPF application in debug mode