title: Binding Visibility Converter in WPF C#
body: <p>I have a dependency property of type collection, when its callback fires based on the count I need to set the visibility of some of the controls on the screen.</p>
  
  <p>But the controls remains Collapsed all the time.
  As per the code, one control remains visible all the time.</p>
  
  <p>XAML binding is </p>
  
  <pre><code>   &lt;TextBlock Text="106 search results for 'a'" Margin="5,0,100,0" Visibility="{Binding CountLabelVisibleReverse, Converter={StaticResource VisibilityConverter}}"/&gt;
   &lt;StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,90,0"  
                              Visibility="{Binding CountLabelVisible, Converter={StaticResource VisibilityConverter}}"&gt;
   &lt;TextBlock Text="Sort By"  /&gt;
   &lt;ComboBox Style="{StaticResource ComboBoxStyle1}" Width="100" x:Name="ComboBoxSorting" ItemsSource="{Binding SortBy}" /&gt;
     &lt;/StackPanel&gt;
  </code></pre>
  
  <p>My two properties are</p>
  
  <pre><code>    public bool CountLabelVisible { get; set; }
  
      public bool CountLabelVisibleReverse { get; set; }
  </code></pre>
  
  <p>Dependency property callback</p>
  
  <pre><code>   private static void ItemsCollectionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs)
      {
          var listingUserControl = (obj as ListingUserControl);
  
          var itemsResult = (eventArgs.NewValue as List&lt;ItemsResult&gt;);
          if (listingUserControl != null &amp;&amp; itemsResult != null)
          {
              listingUserControl.CountLabelVisible = itemsResult.Count &gt; 0;
              listingUserControl.CountLabelVisibleReverse =itemsResult.Count &lt;= 0;
          }
      }
  </code></pre>
  
  <p>Converter code is </p>
  
  <pre><code> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (parameter == null)
              return (bool)value == false ? Visibility.Collapsed : Visibility.Visible;
  
          return (bool)value ? Visibility.Collapsed : Visibility.Visible;
      }
  </code></pre>