/// <summary> /// Finds a DependencyProperty for the specified C# property /// </summary> private DependencyProperty FindStandardProperty(Type originalObjectType, string dependencyProperty) { var propertyType = BindingPropertyHelper.GetPropertyType(originalObjectType, dependencyProperty); if (propertyType != null) { // This line populates the cache for the getter in the BindingPropertyHelper, making the binder // pick it up later on. var setter = BindingPropertyHelper.GetValueSetter(originalObjectType, dependencyProperty, true); var property = DependencyProperty.GetProperty(originalObjectType, dependencyProperty); if (property == null) { // Create a stub property so the BindingPropertyHelper is able to pick up // the plain C# properties. property = DependencyProperty.Register( dependencyProperty, propertyType, originalObjectType, new PropertyMetadata(null) ); } return(property); } else { this.Log().Error($"The property {dependencyProperty} does not exist on {originalObjectType}"); return(null); } }
public void SetBinding(string dependencyProperty, BindingBase binding) { TryRegisterInheritedProperties(force: true); if (dependencyProperty == null) { throw new ArgumentNullException(nameof(dependencyProperty)); } if (binding == null) { throw new ArgumentNullException(nameof(binding)); } var fullBinding = binding as Windows.UI.Xaml.Data.Binding; if (fullBinding != null) { var boundProperty = DependencyProperty.GetProperty(_originalObjectType, dependencyProperty) ?? FindStandardProperty(_originalObjectType, dependencyProperty); if (boundProperty != null) { _properties.SetBinding(boundProperty, fullBinding, _originalObjectRef); } } else { throw new NotSupportedException("Only Windows.UI.Xaml.Data.Binding is supported for bindings."); } }
private static DependencyProperty GetVisibilityProperty(View view) { if (view is FrameworkElement) { return(VisibilityProperty); } else { return(DependencyProperty.GetProperty(view.GetType(), nameof(Visibility))); } }
public void SetBindingValue(object value, [CallerMemberName] string propertyName = null) { var property = DependencyProperty.GetProperty(_originalObjectType, propertyName); if (property != null) { SetBindingValue(value, property); } else { throw new InvalidOperationException($"Binding to a non-DependencyProperty is not supported ({_originalObjectType}.{propertyName})"); } }