public static void SetBinding(this FrameworkElement view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null)
        {
            var binding = bindingBase as Binding;

            updateSourceEventName = updateSourceEventName ?? binding?.UpdateSourceEventName;

            if (IsNullOrEmpty(updateSourceEventName))
            {
                NativePropertyListener nativePropertyListener = null;
                if (bindingBase.Mode == BindingMode.TwoWay)
                {
                    nativePropertyListener = new NativePropertyListener(view, propertyName);
                }

                NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener as INotifyPropertyChanged);
                return;
            }

            NativeEventWrapper eventE = null;

            if (binding.Mode == BindingMode.TwoWay && !(view is INotifyPropertyChanged))
            {
                eventE = new NativeEventWrapper(view, propertyName, updateSourceEventName);
            }

            NativeBindingHelpers.SetBinding(view, propertyName, binding, eventE);
        }
示例#2
0
        static void OnNativePropertyChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            NativePropertyListener source = (NativePropertyListener)sender;

            source?.PropertyChanged?.Invoke(source._target, new PropertyChangedEventArgs(source._targetProperty));
        }