2

I have a static property in my class like

 public partial class ShellWindow { private static Visibility progressbarVisibility = Visibility.Collapsed; public static Visibility ProgressbarVisibility { get { return progressbarVisibility; } set { if (progressbarVisibility == value) return; progressbarVisibility = value; RaiseStaticPropertyChanged("ProgressbarVisibility"); } } public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged; public static void RaiseStaticPropertyChanged(string propName) { EventHandler<PropertyChangedEventArgs> handler = StaticPropertyChanged; if (handler != null) handler(null, new PropertyChangedEventArgs(propName)); } } 

I am creating a control in code behind and wanted to bind it with this property. Currently i am doing like this

var binding = new Binding("ShellWindow.ProgressbarVisibility") { Mode = BindingMode.TwoWay }; binding.Source = this; progressbar = new CircularProgressBar (); progressbar.SetBinding(VisibilityProperty, binding); 

This binding is not working. I am tring to follow this article but i didn't get where i am doing wrong.

1

1 Answer 1

1

In .NET 4.5 you can notify WPF of a change to a static property, however I believe it is different than how you normally handle a property changed. You must create event for each static property that can be notified of a change. The event must be titled with the property name, and have a suffix of PropertyChanged.

I found this article that may help you out: http://10rem.net/blog/2011/11/29/wpf-45-binding-and-change-notification-for-static-properties

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.