Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:50:35+00:00 2026-06-15T10:50:35+00:00

I have a dependency property of type collection, when its callback fires based on

  • 0

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.

But the controls remains Collapsed all the time.
As per the code, one control remains visible all the time.

XAML binding is

   <TextBlock Text="106 search results for 'a'" Margin="5,0,100,0" Visibility="{Binding CountLabelVisibleReverse, Converter={StaticResource VisibilityConverter}}"/>
 <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,90,0"  
                            Visibility="{Binding CountLabelVisible, Converter={StaticResource VisibilityConverter}}">
 <TextBlock Text="Sort By"  />
 <ComboBox Style="{StaticResource ComboBoxStyle1}" Width="100" x:Name="ComboBoxSorting" ItemsSource="{Binding SortBy}" />
   </StackPanel>

My two properties are

    public bool CountLabelVisible { get; set; }

    public bool CountLabelVisibleReverse { get; set; }

Dependency property callback

   private static void ItemsCollectionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs)
    {
        var listingUserControl = (obj as ListingUserControl);

        var itemsResult = (eventArgs.NewValue as List<ItemsResult>);
        if (listingUserControl != null && itemsResult != null)
        {
            listingUserControl.CountLabelVisible = itemsResult.Count > 0;
            listingUserControl.CountLabelVisibleReverse =itemsResult.Count <= 0;
        }
    }

Converter code is

 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;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:50:37+00:00Added an answer on June 15, 2026 at 10:50 am

    You have made the classic mistake of binding to auto properties that are valid for binding, but don’t notify upon change, which means the binding subsystem cannot detect changes and update the binding targets.

    To fix this, implement INotifyPropertyChanged on your viewmodel, and then ensure that you notify the property change from the properties.

    As an example, I have the following in the base class for my viewmodels:

    public abstract class BaseViewModel : INotifyPropertyChanged
    {
    
        /// <summary>
        /// Helper method to set the value of a property and notify if the value has changed.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="newValue">The value to set the property to.</param>
        /// <param name="currentValue">The current value of the property.</param>
        /// <param name="notify">Flag indicating whether there should be notification if the value has changed.</param>
        /// <param name="notifications">The property names to notify that have been changed.</param>
        protected bool SetProperty<T>(ref T newValue, ref T currentValue, bool notify, params string[] notifications)
        {
            if (EqualityComparer<T>.Default.Equals(newValue, currentValue))
                return false;
    
            currentValue = newValue;
            if (notify && notifications.Length > 0)
                foreach (string propertyName in notifications)
                    OnPropertyChanged(propertyName);
    
            return true;
        }
    
        /// <summary>
        /// Raises the <see cref="E:PropertyChanged"/> event.
        /// </summary>
        /// <param name="propertyName">The name of the property that changed.</param>
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    
        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    
    }
    

    then in your regular viewmodel:

    public class MyViewModel : BaseViewModel
    {
        private bool _countLabelVisible;
    
        public bool CountLabelVisible
        {
            get { return _countLabelVisible; }
            set { SetProperty(ref value, ref _countLabelVisible, true, "CountLabelVisible", "CountLabelVisibleReverse"); }
        }
    
        public bool CountLabelVisibleReverse { get { return !_countLabelVisible; }} 
    }
    

    This way, when CountLabelVisible gets changed it also notifies on the property CountLabelVisibleReverse, and the property CountLabelVisibleReverse consists of only a getter – because it will always be the inverse of CountLabelVisible.

    So that fixes your code the way you have it, but the reality is you don’t need to keep the CountLabelVisibleReverse property, instead you could:

    • create an inverse visibility converter as a separate converter
    • create a multi function visibility converter by passing an optional parameter on the binding
    • stack multiple converters, where the output from one converter is piped into the input of the next converter
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string dependency property (SearchText), when updated, needs to update a collection
I have implemented my own usercontrol based on listboxes. It has a dependency property
I have an abstract generic class that defines a generic dependency property the type
I have tried to create a Dependency Property 'IsReadOnly' to automatically set all TextBoxes
I have a custom object type dependency property that is being populated at runtime.
I am using the MVVM model. I have a dependency property, a boolean, called
I have the following dependency property in my MainWindow class (inherits from WPF's Window)
I have the following dependency property inside a class: class FooHolder { public static
I have the following dependency property that works fine but it does not auto
I have a UserControl with a dependency property called ItemsSource . When the property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.