【问题标题】:Binding static assessors wpf C#绑定静态评估器 wpf C#
【发布时间】:2019-02-28 12:11:43
【问题描述】:

早上好。

我想在具有公共静态评估器的类中保留值。例如:

public class Global
{
     public static string Information { get; set; }
     ...
}

我想从 UI 级别更改这些值。我试过这样做:

<TextBox Text="{Binding Source={x:Static Member=local:Global.Information}}"/>

但是发生了错误:

Two-way binding requires Path or XPath.

我一直在寻找答案,但每个解决方案都不适合我。

如何将类中的静态访问器与 Text 属性绑定?

【问题讨论】:

  • 现在出现错误:“全局”类型上的“信息”应为实例成员。所以还是不行。
  • 我看错了,抱歉。 this 能解决你的问题吗?

标签: c# wpf binding static accessor


【解决方案1】:

对静态属性使用此 PropertyPath 语法,自 WPF 4.5 起可用:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 2015-07-30
    相关资源
    最近更新 更多