【发布时间】:2013-05-15 18:55:10
【问题描述】:
考虑下面的例子
public class Test
{
private static string _property = "Success";
public static string Property
{
get { return _property; }
set { _property = value; }
}
public void Check()
{
var prop = new PropertyPath(this.GetType().GetProperty("Property"));
var binding = new Binding();
binding.Source = typeof(Test);
binding.Path = prop;
}
public static void DoTest()
{
new Test().Check();
}
}
当我调用 Test.DoTest() 时,它在我的机器上运行良好,但在其他一些机器上抛出了类似“使用 Binding.Source 时无法分配 Binding.StaticSource”的消息(这不准确,翻译文本)。如果属性不是静态的,那么一切正常。什么可能导致这种行为?
【问题讨论】:
-
如果您的目标是未实现的 Framework 4.0,您希望如何绑定到静态属性?
-
@LPL 它可以在我只安装 .net 4.0 的机器上运行。其实我只需要 OneWayToSource 绑定。
标签: c# .net wpf xaml data-binding