How can I use binding with static property ?

I am using this code but its not working :

IsVisible="{x:Static local:GlobalResources.IsUserLoggedIn}"

This is the class :

public class GlobalResources { public static bool IsUserLoggedIn { get; set; } }

Best Answer


  • fdesbrossesfdesbrosses USMember ✭✭

    What do you mean "not working" ? Not updating when the value changes ? If so, it's normal cause you're not raising PropertyChanged event (GlobalResources should then implementINotifyPropertyChanged interface).

  • mostafamarjimostafamarji USMember

    Yes I am trying to update the value , and I also try to use NotifyPropertyChanged interface but it also doesn't work :

    `public class GlobalResources:INotifyPropertyChanged

        public static bool _isUserLoggedIn { get; set; }
        public  bool IsUserLoggedIn
            get { return _isUserLoggedIn; }
                _isUserLoggedIn = value;
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
            if (PropertyChanged == null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  • KrishTalaKrishTala INMember ✭✭

    Yes, its working.
    Thanks for saving my time.

  • dengerelidengereli TRMember ✭✭

    all are you really sure it is working but is it singleton?

    public static GlobalResources Current = new GlobalResources();

    Current will be produce every called. Please change this below.

    private static GlobalResources _current;
    public static GlobalResources Current => _current ?? (_current = new GlobalResources ());

  • DeepakDYDeepakDY INMember ✭✭✭


    its working
    thanks for help

Sign In or Register to comment.