c# - Binding static assessors wpf C#
问题描述
Good morning.
I would like to keep values in a class with public static assessors. For example:
public class Global
{
public static string Information { get; set; }
...
}
And I want to change these values from UI level. I've tried do it this way:
<TextBox Text="{Binding Source={x:Static Member=local:Global.Information}}"/>
But there occurred an error:
Two-way binding requires Path or XPath.
I was looking for answer but every solution isn't working for me.
How can I bind static accessor from class with Text property?
解决方案
Use this PropertyPath syntax for static properties, which is available since WPF 4.5:
Text="{Binding Path=(local:Global.Information)}"/>
推荐阅读
- ios - Alamofire 中的 TimeoutInterval
- r - 特定条件下 R 中的求和积
- javascript - 如何使用表格中的选定数据打开 Angular 模态窗口
- r - 不能在 R 中使用 sjPlot
- python - 在 Python 中记录到单独的文件
- python - 有没有办法将 BeautifulSoup 与 Facebook 等自扩展页面一起使用?
- python - Pandas - 从行中提取文本
- r - 如何使用 str_detect 在 R 中找到带有简单字符的法语 UTF-8 重音字符?
- android - BLE 与 Lollipop 连接但未与 Nougat 连接
- mysql - 将连接字符串分配给结构的 MySQL 连接属性时出现 NullReferenceException 错误