考慮下面的例子設置Binding.Path拋出的一些機器異常
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()
它工作正常在我的機器上,但拋出InvalidOperationException
包含「消息無法分配Binding.StaticSource當使用Binding.Source 「(這不是確切的,翻譯文本)在其他一些機器上。如果屬性不是靜態的,則一切正常。什麼可能導致這種行爲?
如果您希望綁定到靜態屬性,如果您的目標是未實現此目標的Framework 4.0? – LPL
@LPL好吧,它只適用於安裝了.net 4.0的機器。其實我只需要OneWayToSource綁定。 – Poma