/// <remarks>This overload allows to pass a string <paramref name="path"/> instead of a pathExpression. A pathExpression only uses the part after the last '.', while <paramref name="path"/> allows to specify paths that contain '.'</remarks> public static TDependencyObject BindWithString <TDependencyObject>( this TDependencyObject target, string path = bindingContextPath, BindingMode mode = BindingMode.OneWay, IValueConverter converter = null, object converterParameter = null, string converterLanguage = null, UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default, object source = null, object targetNullValue = default, object fallbackValue = default ) where TDependencyObject : DependencyObject, IDefaultBindProperty { Xaml.Data.BindingOperations.SetBinding( target.UI, target.DefaultBindProperty, new Microsoft.UI.Xaml.Data.Binding { Path = new Xaml.PropertyPath(path), Mode = mode, Converter = converter, ConverterParameter = converterParameter, //ConverterLanguage = converterLanguage, // TODO: figure out correct default; can't be null UpdateSourceTrigger = updateSourceTrigger, Source = source, // TODO: RelativeSource TargetNullValue = targetNullValue, FallbackValue = fallbackValue, } ); return(target); }
/// <summary>Bind to <typeparamref name="TDependencyObject"/>.DefaultBindProperty</summary> /// <param name="pathExpression">viewModel.Property or viewModel.Property1.Property2 or (SomeExpression.viewModel).Property <br />?. can be used safely - viewmodel instance is not required</param> public static TDependencyObject Bind <TDependencyObject>( this TDependencyObject target, object pathExpression = null, BindingMode mode = BindingMode.OneWay, IValueConverter converter = null, object converterParameter = null, string converterLanguage = null, UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default, object source = null, object targetNullValue = default, object fallbackValue = default, [CallerArgumentExpression("pathExpression")] string pathExpressionString = default ) where TDependencyObject : DependencyObject, IDefaultBindProperty => target.BindWithString( Helpers.BindingExpressionToPath(pathExpressionString), mode, converter, converterParameter, converterLanguage, updateSourceTrigger, source, targetNullValue, fallbackValue );
public static void SetBinding(this FrameworkElement self, DependencyProperty property, string path, Microsoft.UI.Xaml.Data.IValueConverter converter) { self.SetBinding(property, new Microsoft.UI.Xaml.Data.Binding { Path = new PropertyPath(path), Converter = converter }); }