绑定到静态类属性 [英] Binding to static class property
本文介绍了绑定到静态类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文本块文本绑定到静态类的属性.每当静态类的属性值发生变化时,它应该反映到另一个窗口或自定义控件上的文本块.
I want to bind a textblock text to a property of a static class. Whenever the property value of the static class changes, it should reflect to the textblock which is on the other window or custom control.
推荐答案
您可以使用 x:Static 标记扩展,但如果您不实施任何更改跟踪,则可能会导致刷新错误!
You can bind to ANY property on a static class using the x:Static markup extension but if thy do not implement any change tracking, it might cause errors on the refresh!
<TextBlock Text="{Binding Source={x:Static sys:Environment.MachineName}}" />
这篇关于绑定到静态类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文