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 4538970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:52:56+00:00 2026-05-21T14:52:56+00:00

Let us assume that we have a simple UI that has only one state

  • 0

Let us assume that we have a simple UI that has only one state variable. This state is expressed as an enum value, eg. Phase1, Phase2 etc. Depending on which state (phase) the UI is, different UI elements, windows supposed to be visible or hidden.

Here is the code:

public enum Phases { Phase1, Phase2, Phase3 }

public class UIStateModel : DependencyObject
{
    public static DependencyProperty CurrentStateProperty =
        DependencyProperty.Register("CurrentStateProperty",
                                    typeof(Phases),
                                    typeof(UIStateModel));
    public Phases CurrentState
    {
        get { return (Phases)GetValue(CurrentStateProperty); }
        set { SetValue(CurrentStateProperty, value); }
    }
    public Visibility Window1Visible // Databound to Window1.Visibility
    {
        get
        {
            if (this.CurrentState == Phases.Phase1) return Visibility.Visible;
            else return Visibility.Hidden;
        }
    }
    public Visibility Window2Visible // Databound to Window2.Visibility
    {
        get
        {
            if (this.CurrentState == Phases.Phase2) return Visibility.Visible;
            else return Visibility.Hidden;
        }
    } 
    ...
}

The problem is that data binding with the code above does not work, because WindowXVisible properties are not DependencyProperty-s. Should I turn all properties to DependencyProperty, then I will introduce redundancy into the state management. Besides the extra burden to keep everything in sync, it can even become inconsistent (if I fail to sync well).

What would be the correct way to avoid introducing redundancy in the UI state management, but still leverage the power of databinding facilitated by DependencyProperty-s?

  • 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-05-21T14:52:57+00:00Added an answer on May 21, 2026 at 2:52 pm

    You can use INotifyPropertyChanged. Simply send a change notification for the given WindowXVisible when CurrentState changes (DP has a callback for this).

    Bindings can generally listen to changes either via DependencyProperty or INotifyPropertyChanged notifications (which must be sent manually though, unlike with DP).

    You can use this tool to generate the notification calls automatically (without increasing complexity of your code by a bit). It handles even such nontrivial cases surprisingly well.

    EDIT:

    Register this into PropertyMetadata of the CurrentStateProperty.

        private static void OnCurrentStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            this.OnPropertyChanged("CurrentState");
            this.OnPropertyChanged("Window1Visible");
            this.OnPropertyChanged("Window2Visible");
        }
    

    OnPropertyChanged simply invokes PropertyChanged event with this as sender and the string as property name.

    This will cause Window1Visible and Window2Visible bindings to update and get the new values.

    By the way, you should try to figure out better names than Window1 and WIndow2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume I have a model called product. Let's assume that product has three
This is one of those little detail (and possibly religious) questions. Let's assume we're
Let's assume that I have defined two Grid s and few TextBox es in
Let's assume that some developer in my team shelved his changes that he did
Let's for a moment assume that you're programming in a language that uses camelcase
Let's assume, we create a stored procedure that is supposed to retrieve customer details
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
Or vice versa. Update: Hmm, let's assume I have a shopping cart app, the
Firstly, let me set out what I'd like to do. Assume I have three
I have an app that has a tabBar Controller and a navBar Controller. It

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.