title: Multiple Datatemplates & Grid.IsSharedSizeScope - Not aligning to content width
body: <p>I have a listbox in which I render data using multiple datatemplates, and I use a datatemplate selector to route data to the appropriate template.</p>
  
  <p>Each template has it's own layout using a grid. The first column of every grid inside the template is a textblock and I want them aligned  to left. The next item is another textblock which should be aligned towards the maximum width of the first textblock (something similar to a data entry form). I'm using Grid.IsSharedSizeScope for this, but not able to achieve this. Below is my code:</p>
  
  <pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;      
  
  &lt;Page.Resources&gt;
  
   &lt;DataTemplate x:Key="DefaultTemplate"&gt;
              &lt;Border BorderThickness="1" CornerRadius="3" BorderBrush="LightGray"&gt;
              &lt;TextBlock Text="{Binding Name}"&gt;&lt;/TextBlock&gt;
              &lt;/Border&gt;
          &lt;/DataTemplate&gt;
          &lt;DataTemplate x:Key="ShortFieldTemplate"&gt;
              &lt;Grid Grid.IsSharedSizeScope="True"&gt;
  
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="Auto" SharedSizeGroup="A"/&gt;
                      &lt;ColumnDefinition/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;  
                  &lt;TextBlock Text="Age:"  Grid.Column="0"&gt;&lt;/TextBlock&gt;
                  &lt;TextBlock Text="{Binding Age}" Grid.Column="1"&gt;&lt;/TextBlock&gt;
              &lt;/Grid&gt;            
          &lt;/DataTemplate&gt;
          &lt;DataTemplate x:Key="LongFieldTemplate"&gt;
              &lt;Grid Grid.IsSharedSizeScope="True"&gt;
  
                      &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="Auto" SharedSizeGroup="A"/&gt;
                          &lt;ColumnDefinition/&gt;                        
                      &lt;/Grid.ColumnDefinitions&gt;               
                  &lt;TextBlock Text="This should be the name:" Grid.Column="0"&gt;&lt;/TextBlock&gt;
                  &lt;TextBlock Text="{Binding Name}" Grid.Column="1"&gt;&lt;/TextBlock&gt;                
                  &lt;/Grid&gt;                      
          &lt;/DataTemplate&gt;
  
          &lt;GridSplitterTextTrim:MyFirstTemplateSelector x:Key="MyFirstTemplateSelector" 
                                                        DefaultDataTemplate="{StaticResource DefaultTemplate}"
                                                        ShortFieldDataTemplate="{StaticResource ShortFieldTemplate}"
                                                        LongFieldDataTemplate="{StaticResource LongFieldTemplate}"
                                                        /&gt;
  
  &lt;/Page.Resources&gt;
  
     &lt;Grid x:Name="LayoutRoot" Grid.IsSharedSizeScope="True"&gt;
  
      &lt;Grid Grid.Column="2" Background="Green" &gt;
  
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;ColumnDefinition/&gt;
                  &lt;ColumnDefinition/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition/&gt;
                  &lt;RowDefinition/&gt;
                  &lt;RowDefinition/&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;ListBox ItemsSource="{Binding Items}" Grid.Row="0" Grid.Column="0" x:Name="listbox" ItemTemplateSelector="{StaticResource MyFirstTemplateSelector}"&gt;  
              &lt;/ListBox&gt;
          &lt;/Grid&gt;   
     &lt;/Grid&gt;  
  &lt;/Page&gt;   
  </code></pre>
  
  <p>..and my object model</p>
  
  <pre><code> public class ShortField : INotifyPropertyChanged
      {
          private string _name;
          public string Age
          {
              get { return _name; }
              set
              {
                  _name = value;
                  InvokePropertyChanged(new PropertyChangedEventArgs("Age"));
              }
          }
  
          private string _currentValue;
          public string CurrentValue
          {
              get { return _currentValue; }
              set
              {
                  _currentValue = value;
                  InvokePropertyChanged(new PropertyChangedEventArgs("CurrentValue"));
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          public void InvokePropertyChanged(PropertyChangedEventArgs e)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
              if (handler != null) handler(this, e);
          }
  
          public static List&lt;ShortField&gt; GetShortFields()
          {
              return new List&lt;ShortField&gt;()
                         {
                             new ShortField() {Age = "10"},
                             new ShortField() {Age = "21"},
                         };
          }
      }
  </code></pre>
  
  <p>How do I get this alignment right? I thought Grid.IsSharedScope should do the trick. Is that correct or is there any other way?</p>
  
  <p>Thanks in advance,
  -Mike</p>