public void Should_Not_Pass_UnsetValue_To_MultiBinding_During_ApplyTemplate() { var converter = new MultiConverter(); var source = new Button { Content = "foo", Template = new FuncControlTemplate <Button>((parent, _) => new ContentPresenter { [~ContentPresenter.ContentProperty] = new MultiBinding { Converter = converter, Bindings = { new TemplateBinding(ContentControl.ContentProperty), } } }), }; source.ApplyTemplate(); var target = (ContentPresenter)source.GetVisualChildren().Single(); // #8672 was caused by TemplateBinding passing "unset" to the MultiBinding during // ApplyTemplate as the TemplatedParent property doesn't get setup until after the // binding is initiated. Assert.Equal(new[] { "foo" }, converter.Values); }
public void MultiConverter(object value) { var multiConverter = new MultiConverter(); var result = multiConverter.Convert(value, typeof(MultiConverter), null, CultureInfo.CurrentCulture); Assert.AreEqual(result, value); }
/// <inheritdoc/> public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { if (MultiConverter == null) { throw new InvalidOperationException("No multi value converter has been set."); } var result = chainedConverter.ConvertBack(value, MultiConverterTargetType ?? typeof(object), parameter, culture); return(MultiConverter.ConvertBack(result, targetTypes, MultiConverterParameter, culture)); }
public DuoBinding(string path1, object source1, string path2, object source2) : base() { Converter = new MultiConverter <object[]>(i => i.Values); Bindings.Add(new Binding() { Mode = BindingMode.OneWay, Path = new System.Windows.PropertyPath(path1), Source = source1 }); Bindings.Add(new Binding() { Mode = BindingMode.OneWay, Path = new System.Windows.PropertyPath(path2), Source = source2 }); }
public BindingLoc(string path) : base() { Converter = new MultiConverter <string>(data => { if (data.Values?.Length > 0) { try { var culture = LocalizeDictionary.Instance.SpecificCulture; var key = data.Values[0].ToString(); var value = LocExtension.GetLocalizedValue(data.TargetType, key, culture, null); if (value == null) { var missingKeyEventResult = LocalizeDictionary.Instance.OnNewMissingKeyEvent(this, key); if ( LocalizeDictionary.Instance.OutputMissingKeys && !string.IsNullOrEmpty(key) && (data.TargetType == typeof(string) || data.TargetType == typeof(object)) ) { value = missingKeyEventResult.MissingKeyResult != null ? missingKeyEventResult.MissingKeyResult : "Key: " + key; } } var result = $"{Prefix}{value}{Suffix}"; result = Format?.F(result) ?? result; result = Lower ? result.ToLower() : Upper ? result.ToUpper() : result; return(result); } catch { } } return(null); }); KeyBinding = new Binding(path); Bindings.Add(KeyBinding); Bindings.Add(new Markup.Options() { Path = new PropertyPath("Language") }); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var val1 = System.Convert.ToDouble(MultiConverter.Convert(values, null, null, culture)); return(SingleConverter.Convert(val1, targetType, parameter, culture)); }