1

ApplicationException: Binding.StaticSource cannot be set while using Binding.Source.このコードは 4.0 で機能しますが、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

1 に答える 1