1
此代碼工作在4.0,但拋出ApplicationException: Binding.StaticSource cannot be set while using Binding.Source.
在4.5:.NET 4.5斷裂靜態綁定
public class Test
{
public static string Prop { get; set; }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var binding = new Binding
{
Source = typeof(Test),
Path = new PropertyPath(typeof(Test).GetProperty("Prop")),
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(textBox1, TextBox.TextProperty, binding);
}
有沒有解決辦法?目標是以編程方式綁定到靜態屬性(OneWayToSource),而不實例化Test
。
謝謝,它的工作原理。我的代碼在4.0中運行。 – Poma