title: XAML C# Hide Grid Row
body: <p>I have a grid where I am trying to hide a row which contains a text box using c# as my code behind.  <strong>My end goal</strong> is to find a way to set text in the text box while the row is hidden hidden.  I may run into problems where wpf does not allow text to be set in a textbox if the size of the textbox is smaller than the font size.  This is what I have so far:</p>
  
  <p>XAML:</p>
  
  <pre><code>Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="100"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition Height="100"/&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;Button x:Name="Button1"
                  Grid.Row="2"
                  Grid.Column="1"
                  Width="100"
                  Height="50"
                  Click="OnClick"
                  Content="Hide Middle Row"/&gt;
  
      &lt;Grid x:Name="AddressBar" Grid.Row="1" Grid.Column="2"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
        &lt;TextBlock x:Name="Block1"
                  FontSize="16"
                  Grid.ColumnSpan="3"
                  HorizontalAlignment="Center"
                  TextAlignment="Center"/&gt;
  
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>namespace rowCollapseTest
  {
  
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void OnClick(object sender, RoutedEventArgs e)
          {
              AddressBar.RowDefinitions(1).Height = new GridLength(0);
              AddressBar.Visibility = Visibility.Collapsed;
              Block1.Text = "This is a test";
          }
      }
  }
  </code></pre>
  
  <p>From what I have read, this should work.  However, I am receiving an error concerning "RowDefinitions(1)".  The error reads: "Non-invocable member 'Grid.RowDefinitions' cannot be used like a method."  Any ideas?</p>
  
  <p>Thanks in advance!</p>