title: C# WPF change grid visibility if combobox item is selected
body: <p>I'm trying to display a <code>Grid</code>and its contents when an item (anyone) in <code>combobox</code> is selected. If nothing is selected, grid will remain hidden.</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>    &lt;ComboBox x:Name="cb" HorizontalAlignment="Left" VerticalAlignment="Top" Width="140" Height="25"/&gt;
      &lt;Grid x:Name="gr" Visibility="Hidden"&gt;
              &lt;Border BorderThickness="1" HorizontalAlignment="Left" Height="600"  VerticalAlignment="Top" Width="346"&gt;
                  &lt;Border  BorderThickness="1" RenderTransformOrigin="0.5,0.5"&gt;
              &lt;/Border&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>I've tried with this:</p>
  
  <p><strong>XAML.CS</strong></p>
  
  <pre><code>public void ChangeVisibility(ComboBox cb, Grid gr)
      {
          if (cb.SelectedItem != null)
          {
              gr.Visibility = Visibility.Visible;
          }
          else
          {
              gr.Visibility = Visibility.Hidden;
          }
  </code></pre>
  
  <p>But it doesn't change anything. I've tried in multiple ways, even with <code>string.IsNullOrEmpty</code>.
  Source of <code>combobox</code> is a <code>List&lt;string&gt;</code>.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Method is called here</p>
  
  <pre><code>public MainWindow()
          {
              InitializeComponent();
              WindowStartupLocation = WindowStartupLocation.CenterScreen;
              ChangeVisibility(cb, gr);
          }
  </code></pre>