绑定到静态属性 [英] Binding to static class property

查看:115
本文介绍了绑定到静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给TextBlock文本静态类的属性绑定。每当静态类变动的属性值,它应该反映这是对其他窗口或自定义控制文本块。

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:!静态标记扩展,但如果你不执行任何更改跟踪,这可能导致在刷新错误

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆