How to bind in XAML to a static property?

前端 未结 3 811
挽巷
挽巷 2021-01-25 02:47

I am trying to bind a static property of a different class to the Text Property of a TextBlock and can get the binding to work, but there\'s is no update to the Text Property wh

相关标签:
3条回答
  • 2021-01-25 03:25

    Binding to static property is a problem (and unavailable in WPF) becuse of change notification (implementing INotifyPropertyChanged for static properties). Binding to static property will be introduced in WPF 4.5 (you can check it by installing .NET 4.5 Developer Preview). More details about it can be found here.

    0 讨论(0)
  • 2021-01-25 03:31

    This is not currently possible, but will be in .NET 4.5: Also see "WPF 4.5 – Part 9 : binding to static properties"

    There is a workaround posted in this SO thread: Binding to static property

    0 讨论(0)
  • 2021-01-25 03:39

    In case this helps anyone else out I figured I'd post my final solution which works quite well for my purpose.

    Since it turns out not to be possible without .NET 4.5 I ended up changing the property and methods to no longer be static and changed the class to a singleton then implemented INotfiyPropertyChanged and changed the XAML binding source to x:Static instead of creating an instance in Window.Resources.

    0 讨论(0)
提交回复
热议问题