首页 > 解决方案 > 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?

标签: c#wpfbindingstaticaccessor

解决方案


Use this PropertyPath syntax for static properties, which is available since WPF 4.5:

Text="{Binding Path=(local:Global.Information)}"/>

推荐阅读