Tag: 双向绑定

与转换器的双向数据绑定不会更新源

我有一个数据绑定设置与转换器,以将一个笨拙的XML源转换为显示和编辑方便的内部类树。 一切都非常适合从XML源读取,但我有一段时间试图对内部类进行更改以传播回XML源。 这是使用网站的XAML: XmlSource是父数据绑定对象的CLR读写属性(不是DependencyProperty)。 它是从XSD生成的.NET类型。 SampleConverter实现了IValueConverter 。 调用Convert方法并返回非空数据,但从不调用ConvertBack方法。 SampleControl是一个UserControl,它封装了与Sample数据树的UI交互。 这是XAML看起来像这样: [… other stuff …] Sample属性是SampleControl代码中的DependencyProperty: public static readonly DependencyProperty SampleProperty = DependencyProperty.Register(“Sample”, typeof(SampleType), typeof(SampleControl), new PropertyMetadata(new PropertyChangedCallback(OnSampleChanged))); public SampleType Sample { get { return (SampleType)GetValue(SampleProperty); } set { SetValue(SampleProperty, value); } } private static void OnSampleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null) { […]