title: How to keep gridsplitter seempless scrolling in ListBox control
body: <p>I have a <code>ListBox</code> with <code>Grid</code> in its data template. In <code>Grid</code> I have a <code>Splitter</code> control. Now the problem is: when I bind the item source of list box then multiple grid are generated internally and because of those grids my splitter control is not working. It is working unpredictably. This means that when I move splitter control to left side it moves smoothly but when I try to move it from another row it does not move back. Kindly help me about this matter. </p>
  
  <p>Please see the sample code for more references:</p>
  
  <pre><code>&lt;Window x:Class="MultiColumnList.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:MultiColumnList"
  Title="Window1" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="400" d:DesignWidth="400" SizeToContent="WidthAndHeight"&gt;
  &lt;Grid &gt;
      &lt;Grid.Resources&gt;
          &lt;XmlDataProvider x:Key="BlogData" XPath="Blogs/Blog"&gt;
              &lt;x:XData&gt;
                  &lt;Blogs xmlns=""&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;simplegeek.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Offline"&gt;Chris Anderson&lt;/Blogger&gt;
                          &lt;Url&gt;http://simplegeek.com&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;fortes.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Offline"&gt;Fil Fortes&lt;/Blogger&gt;
                          &lt;Url&gt;http://fortes.com/work&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;Longhorn Blogs&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Rob Relyea&lt;/Blogger&gt;
                          &lt;Url&gt;http://www.longhornblogs.com/rrelyea/&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;designerslove.net&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Nathan Dunlap&lt;/Blogger&gt;
                          &lt;Url&gt;http://designerslove.net/&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;blogs.msdn.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Karsten Januszewski&lt;/Blogger&gt;
                          &lt;Url&gt;http://blogs.msdn.com/karstenj&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;weblogs.asp.net&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Greg Schecter&lt;/Blogger&gt;
                          &lt;Url&gt;http://weblogs.asp.net/greg_schechter&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;blogs.msdn.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Tim Sneath&lt;/Blogger&gt;
                          &lt;Url&gt;http://blogs.msdn.com/tims/&lt;/Url&gt;
                      &lt;/Blog&gt;
  
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;weblogs.asp.net&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Offline"&gt;Marcelo Lopez-Ruiz&lt;/Blogger&gt;
                          &lt;Url&gt;http://weblogs.asp.net/marcelolr/&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;blogs.msdn.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Online"&gt;Kevin Moore&lt;/Blogger&gt;
                          &lt;Url&gt;http://blogs.msdn.com/okoboji/default.aspx&lt;/Url&gt;
                      &lt;/Blog&gt;
                      &lt;Blog&gt;
                          &lt;BlogSite&gt;laurenlavoie.com&lt;/BlogSite&gt;
                          &lt;Blogger OnlineStatus="Offline"&gt;Lauren Lavoie&lt;/Blogger&gt;
                          &lt;Url&gt;http://laurenlavoie.com/&lt;/Url&gt;
                      &lt;/Blog&gt;
                  &lt;/Blogs&gt;
              &lt;/x:XData&gt;
          &lt;/XmlDataProvider&gt;
  
          &lt;DataTemplate x:Key="BlogDataTemplate"&gt;
  
              &lt;Grid TextBlock.FontSize="12" LayoutUpdated="Grid_LayoutUpdated"&gt;
  
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition x:Name="LeftColumn" Width="Auto"   SharedSizeGroup="BloggerColumn"/&gt;
                      &lt;ColumnDefinition  x:Name="Center" Width="*"  SharedSizeGroup="BlogSiteColumn"/&gt;
                      &lt;ColumnDefinition x:Name="Right" Width="*"  SharedSizeGroup="OnlineStatusColumn"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;TextBlock Grid.Column="0" Margin="10,0,10,0" Text="{Binding XPath=Blogger}"/&gt;
                  &lt;GridSplitter Grid.Column="1" Width="2"  HorizontalAlignment="Center" Background="Black"  DragCompleted="GridSplitter_DragCompleted"/&gt;
  
                  &lt;TextBlock Grid.Column="2" Margin="10,0,10,0" Text="{Binding XPath=Blogger/@OnlineStatus}"/&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
  
          &lt;ControlTemplate x:Key="Header" TargetType="{x:Type Button}"&gt;
              &lt;Border Background="LightGray" 
                  TextBlock.Foreground="white" 
                  TextBlock.FontSize="20" 
                  Padding="10,3,10,4"&gt;
                  &lt;ContentPresenter/&gt;
              &lt;/Border&gt;
          &lt;/ControlTemplate&gt;
  
          &lt;Grid x:Key="ListHeader" Margin="5" &gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto" SharedSizeGroup="BloggerColumn"/&gt;
                  &lt;ColumnDefinition Width="*" SharedSizeGroup="BlogSiteColumn"/&gt;
                  &lt;ColumnDefinition Width="*" SharedSizeGroup="BloggerOnlineStatusColumn"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Button Grid.Column="0" Template="{StaticResource Header}"&gt;Blogger&lt;/Button&gt;
              &lt;GridSplitter Grid.Column="1" Width="2"  Background="Black" HorizontalAlignment="Stretch" DragCompleted="GridSplitter_DragCompleted"  /&gt;
              &lt;Button Grid.Column="2" Template="{StaticResource Header}"&gt;Status&lt;/Button&gt;
          &lt;/Grid&gt;
  
  
          &lt;Style x:Key="HeaderedScrollViewer" TargetType="{x:Type ScrollViewer}"&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type ScrollViewer}"&gt;
                          &lt;Grid Background="{TemplateBinding Background}"&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="*"/&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition Height="*"/&gt;
                                  &lt;RowDefinition Height="Auto"/&gt;
                              &lt;/Grid.RowDefinitions&gt;
  
                              &lt;DockPanel Margin="{TemplateBinding Padding}"&gt;
                                  &lt;ScrollViewer DockPanel.Dock="Top"
                                            local:SetHorizontalOffset.Offset="{Binding 
                                                  RelativeSource={RelativeSource TemplatedParent}, 
                                                  Path=HorizontalOffset}" 
                                            HorizontalScrollBarVisibility="Hidden"
                                            VerticalScrollBarVisibility="Hidden"
                                            Focusable="false"
                                            Content="{StaticResource ListHeader}"&gt;
                                  &lt;/ScrollViewer&gt;
  
                                  &lt;ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"/&gt;
                              &lt;/DockPanel&gt;
  
                              &lt;ScrollBar Name="PART_HorizontalScrollBar"
                                  Orientation="Horizontal"
                                  Grid.Row="1"
                                  Maximum="{TemplateBinding ScrollableWidth}"
                                  ViewportSize="{TemplateBinding ViewportWidth}"
                                  Value="{TemplateBinding HorizontalOffset}"
                                  Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/&gt;
  
                              &lt;ScrollBar Name="PART_VerticalScrollBar"
                                  Grid.Column="1"
                                  Maximum="{TemplateBinding ScrollableHeight}"
                                  ViewportSize="{TemplateBinding ViewportHeight}"
                                  Value="{TemplateBinding VerticalOffset}"
                                  Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/&gt;
                          &lt;/Grid&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
          &lt;Style x:Key="{x:Type ListBox}" TargetType="{x:Type ListBox}"&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate&gt;
                          &lt;ScrollViewer Style="{StaticResource HeaderedScrollViewer}" 
                                        Grid.IsSharedSizeScope="True"&gt;
                              &lt;StackPanel IsItemsHost="true"/&gt;
                          &lt;/ScrollViewer&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
      &lt;/Grid.Resources&gt;
  
      &lt;ListBox ItemsSource="{Binding Source={StaticResource BlogData}}" 
               ItemTemplate="{StaticResource BlogDataTemplate}" Height="400" Width="600"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>