title: Wpf changing Visibility from code behind
body: <p>I am trying to change the visiblity of my datagrid from code behind but it's not working </p>
  
  <pre><code> private void afch_data_Click(object sender, System.Windows.RoutedEventArgs e)
      {
          if (donne_compte.IsVisible) // this is a grid and It's visible
          {
             dgComptes.Visibility = Visibility.Visible; 
             //when I breakpoint here , I find that the datagrid visibilty   `property is still set to hidden  
  
          }
      }
  </code></pre>
  
  <p>EDIT 
  here s my datagrid Xaml It's a simple one : </p>
  
  <pre><code>&lt;DataGrid x:Name="dgComptes" CanUserAddRows="False"   IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding ComCollection}"  RowHeaderWidth="0"  HorizontalScrollBarVisibility="Disabled"  HorizontalAlignment="Left" Margin="529.534,84.016,-390.033,0" VerticalAlignment="Top" Height="Auto"  MaxHeight="200"  Width="395.429" RenderTransformOrigin="0.5,0.5" Background="#FFCFCFCF"  ColumnWidth="*" HorizontalGridLinesBrush="Black" VerticalGridLinesBrush="Black" RowBackground="#FFCFCFCF" AreRowDetailsFrozen="True" Style="{DynamicResource DataGridStyle2}" CellEditEnding="dataGrid1_CellEditEnding" CurrentCellChanged="dataGrid1_CurrentCellChanged" SelectionChanged="dataGrid1_SelectionChanged" AutoGeneratingColumn="dataGrid1_AutoGeneratingColumn" AutoGenerateColumns="False" &gt;
  
                  &lt;DataGrid.Columns &gt;
  
                      &lt;DataGridTemplateColumn x:Name="champ_supp2" &gt;
                          &lt;DataGridTemplateColumn.CellTemplate &gt;
                              &lt;DataTemplate&gt;
                                  &lt;Button x:Name="supprime" Content="Button" Width="30" Height="30" Style="{DynamicResource ButtonStyle12}" Click="supprime_Click"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/DataGridTemplateColumn.CellTemplate&gt;
                      &lt;/DataGridTemplateColumn&gt;
  
  
                      &lt;DataGridTextColumn   Header="Id"  Binding="{Binding ID}" /&gt;
                      &lt;DataGridTextColumn   Header="Taille"  Binding="{Binding TAILLE}"  /&gt;
                      &lt;DataGridTextColumn   Header="Client" Binding="{Binding CLIENT}"   /&gt;
                      &lt;DataGridTextColumn   Header="D.arrivée" Binding="{Binding D_ARRIVEE}"   /&gt;
                      &lt;DataGridTextColumn   Header="D.départ" Binding="{Binding D_DEPART}"   /&gt;
  
                  &lt;/DataGrid.Columns&gt;
  
  
  
              &lt;/DataGrid&gt;
  </code></pre>