public static void BindingProperty(FrameworkElement targetElement, DependencyProperty targetProperty, DependencyObject source, DependencyProperty childObjProperty, FrameworkElement defaultSource, DependencyProperty defaultSourceProperty) { var isDefault = DependencyObjectUtils.IsDefaultValue(source, childObjProperty); var bindingProperty = isDefault ? defaultSourceProperty : childObjProperty; var actualSource = isDefault ? defaultSource : source; BindingProperty(targetElement, targetProperty, actualSource, bindingProperty); }
public static void BindingPropertyIfNonDefault(FrameworkElement element, DependencyProperty targetProperty, DependencyObject source, DependencyProperty sourceProperty, BindingMode mode = BindingMode.OneWay) { if (DependencyObjectUtils.IsDefaultValue(source, sourceProperty)) { var binding = new Binding() { Path = new PropertyPath(sourceProperty), Source = source, Mode = mode, }; element.SetBinding(targetProperty, binding); } }
public static void BindingPropertyIfNonDefault(FrameworkElementFactory factory, DependencyProperty targetProperty, DependencyObject source, DependencyProperty sourceProperty, IValueConverter converter, BindingMode mode = BindingMode.OneWay) { if (!DependencyObjectUtils.IsDefaultValue(source, sourceProperty)) { var binding = new Binding() { Path = new PropertyPath(sourceProperty), Source = source, Mode = mode, Converter = converter, }; factory.SetBinding(targetProperty, binding); } }