title: How to set custom layout grid position to StatusBarItem programmatically?
body: <p>I want a dynamic status bar in my project</p>
  
  <p>So I set the ItemSource to Binding</p>
  
  <pre><code>&lt;StatusBar ItemsSource="{Binding StatusBarItemsSource}" DockPanel.Dock="Bottom" &gt;
  </code></pre>
  
  <p>And created a BindingList in my main view model</p>
  
  <pre><code>public static BindingList&lt;StatusBarItem&gt; StatusBarItemsSource { get; set; }
  </code></pre>
  
  <p>On the initialization I add my logo to the bottom right</p>
  
  <pre><code>StatusBarItem logo = new StatusBarItem
  {
      HorizontalAlignment = HorizontalAlignment.Right,
      Content = new Image
      {
          Source = new BitmapImage(new Uri("Logo.ico", UriKind.Relative)),
          Width = 16,
          Height = 16
      }
  };
  StatusBarItemsSource.Add(logo); 
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/VEbtu.png" alt="StatusBar with logo on the right"></p>
  
  <p>So far so good, the logo appears in the right corner</p>
  
  <p>BUT</p>
  
  <p>If I want to add another StatusBarItem in another view to display a sum text for the view on the left, the logo shows up on the left too</p>
  
  <p>MainViewModel:</p>
  
  <pre><code>public static void AddItemToStatusBar(Object content, HorizontalAlignment alignment = HorizontalAlignment.Stretch)
  {
      StatusBarItem statusBarItem = new StatusBarItem
      {
          HorizontalAlignment = alignment,
          Content = content
      };
      StatusBarItemsSource.Add(statusBarItem);
  }
  </code></pre>
  
  <p>Another ViewModel:</p>
  
  <pre><code>TextBlock someTextBlock = new TextBlock { Text = someString };
  MainViewModel.AddItemToStatusBar(someTextBlock , System.Windows.HorizontalAlignment.Left);
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/TwgMK.png" alt="StatusBar with logo and some Text on the left"></p>
  
  <p>Then I found here on stackoverflow the possibility to set a grid as a template <a href="https://stackoverflow.com/questions/1373529/how-do-i-customize-the-wpf-statusbar-layout">How do I customize the WPF StatusBar layout?</a> </p>
  
  <p>So i added this to my code:</p>
  
  <pre><code>&lt;StatusBar ItemsSource="{Binding StatusBarItemsSource}" DockPanel.Dock="Bottom" &gt;
      &lt;StatusBar.ItemsPanel&gt;
          &lt;ItemsPanelTemplate&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="100" /&gt;
                      &lt;ColumnDefinition Width="Auto" /&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                      &lt;ColumnDefinition Width="Auto" /&gt;
                      &lt;ColumnDefinition Width="100" /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
              &lt;/Grid&gt;
          &lt;/ItemsPanelTemplate&gt;
      &lt;/StatusBar.ItemsPanel&gt;
  &lt;/StatusBar&gt;
  </code></pre>
  
  <p>How to define the column in XAML is clear</p>
  
  <pre><code>&lt;StatusBarItem Grid.Column="3"&gt;
      &lt;TextBlock&gt;some String&lt;/TextBlock&gt;
  &lt;/StatusBarItem&gt;
  </code></pre>
  
  <p><strong>But how to do this in my view model?</strong></p>
  
  <p>i have tried something like     <code>statusBarItem.Grid.Column = 3 / "3"</code> or <code>statusBarItem.Grid.SetColumn</code> but without success</p>
  
  <p>I hope you can help me and this little question has not taken too large extent</p>