Beispiel #1
0
 /// <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);
 }
Beispiel #2
0
 /// <summary>Bind to the default property with inline conversion</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, TPropertyValue, TSource>(
     this TDependencyObject target,
     object pathExpression = null,
     BindingMode mode      = BindingMode.OneWay,
     Func <TSource, TPropertyValue> convert     = null,
     Func <TPropertyValue, TSource> convertBack = null,
     string converterLanguage = null,
     UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default,
     object source = null,
     TPropertyValue targetNullValue = default,
     [CallerArgumentExpression("pathExpression")] string pathExpressionString = default
     ) where TDependencyObject : DependencyObject, IDefaultBindProperty
 => target.BindWithString(
     Helpers.BindingExpressionToPath(pathExpressionString),
     mode,
     new FuncConverter <TSource, TPropertyValue, object>(convert, convertBack),
     null,
     converterLanguage,
     updateSourceTrigger,
     source,
     targetNullValue
     );
Beispiel #3
0
 /// <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
     );