public void BindSpecifiedPropertyWithPositionalParameters() => AssertExperimental(() => { var button = new Button(); object converterParameter = 1; string stringFormat = nameof(BindSpecifiedPropertyWithPositionalParameters) + " {0}"; IValueConverter converter = new ToStringConverter(); object source = new ViewModel(); object targetNullValue = nameof(BindSpecifiedPropertyWithPositionalParameters) + " null"; object fallbackValue = nameof(BindSpecifiedPropertyWithPositionalParameters) + " fallback"; button.Bind( Button.TextProperty, nameof(viewModel.Text), BindingMode.OneWay, converter, converterParameter, stringFormat, source, targetNullValue, fallbackValue ); BindingHelpers.AssertBindingExists( button, targetProperty: Button.TextProperty, path: nameof(viewModel.Text), mode: BindingMode.OneWay, converter: converter, converterParameter: converterParameter, stringFormat: stringFormat, source: source, targetNullValue: targetNullValue, fallbackValue: fallbackValue ); });
public void BindDefaultPropertyWithInlineTwoWayParameterizedConvertAndPositionalParameters() => AssertExperimental(() => { var label = new Label(); object converterParameter = 1; string stringFormat = nameof(BindDefaultPropertyWithInlineTwoWayParameterizedConvertAndPositionalParameters) + " {0}"; object source = new ViewModel(); object targetNullValue = nameof(BindDefaultPropertyWithInlineTwoWayParameterizedConvertAndPositionalParameters) + " null"; object fallbackValue = nameof(BindDefaultPropertyWithInlineTwoWayParameterizedConvertAndPositionalParameters) + " fallback"; label.Bind( nameof(viewModel.Text), BindingMode.TwoWay, (string text, int repeat) => string.Concat(Enumerable.Repeat($"'{text?.Trim('\'')}'", repeat)), (text, repeat) => text?.Substring(0, text.Length / repeat).Trim('\''), converterParameter, stringFormat, source, targetNullValue, fallbackValue ); BindingHelpers.AssertBindingExists( label, targetProperty: Label.TextProperty, path: nameof(viewModel.Text), mode: BindingMode.TwoWay, assertConverterInstanceIsAnyNotNull: true, converterParameter: converterParameter, stringFormat: stringFormat, source: source, targetNullValue: targetNullValue, fallbackValue: fallbackValue, assertConvert: c => c.AssertConvert("test", 2, "'test''test'", twoWay: true) ); });
public void BindDefaultPropertyWithInlineOneWayConvertAndPositionalParameters() => AssertExperimental(() => { var label = new Label(); object converterParameter = 1; string stringFormat = nameof(BindDefaultPropertyWithInlineOneWayConvertAndPositionalParameters) + " {0}"; object source = new ViewModel(); object targetNullValue = nameof(BindDefaultPropertyWithInlineOneWayConvertAndPositionalParameters) + " null"; object fallbackValue = nameof(BindDefaultPropertyWithInlineOneWayConvertAndPositionalParameters) + " fallback"; label.Bind( nameof(viewModel.Text), BindingMode.OneWay, (string text) => $"'{text?.Trim('\'')}'", null, converterParameter, stringFormat, source, targetNullValue, fallbackValue ); BindingHelpers.AssertBindingExists( label, targetProperty: Label.TextProperty, path: nameof(viewModel.Text), mode: BindingMode.OneWay, assertConverterInstanceIsAnyNotNull: true, converterParameter: converterParameter, stringFormat: stringFormat, source: source, targetNullValue: targetNullValue, fallbackValue: fallbackValue, assertConvert: c => c.AssertConvert("test", "'test'") ); });
public void BindTapGestureDefaults() => AssertExperimental(() => { var gestureElement = new TGestureElement(); gestureElement.BindTapGesture(commandPath); var gestureRecognizer = AssertHasGestureRecognizer <TapGestureRecognizer>(gestureElement); BindingHelpers.AssertBindingExists(gestureRecognizer, TapGestureRecognizer.CommandProperty, commandPath); });
public void BindCommandWithoutParameter() => AssertExperimental(() => { var textCell = new TextCell(); string path = nameof(viewModel.Command); textCell.BindCommand(path, parameterPath: null); BindingHelpers.AssertBindingExists(textCell, TextCell.CommandProperty, path); Assert.That(BindingHelpers.GetBinding(textCell, TextCell.CommandParameterProperty), Is.Null); });
public void BindCommandWithDefaults() => AssertExperimental(() => { var textCell = new TextCell(); string path = nameof(viewModel.Command); textCell.BindCommand(path); BindingHelpers.AssertBindingExists(textCell, TextCell.CommandProperty, path); BindingHelpers.AssertBindingExists(textCell, TextCell.CommandParameterProperty); });
public void BindTapGesturePositionalParameters() => AssertExperimental(() => { var gestureElement = new TGestureElement(); object commandSource = new ViewModel(); object parameterSource = new ViewModel(); gestureElement.BindTapGesture(commandPath, commandSource, parameterPath, parameterSource); var gestureRecognizer = AssertHasGestureRecognizer <TapGestureRecognizer>(gestureElement); BindingHelpers.AssertBindingExists(gestureRecognizer, TapGestureRecognizer.CommandProperty, commandPath, source: commandSource); BindingHelpers.AssertBindingExists(gestureRecognizer, TapGestureRecognizer.CommandParameterProperty, parameterPath, source: parameterSource); });
public void BindCommandWithPositionalParameters() => AssertExperimental(() => { var textCell = new TextCell(); object source = new ViewModel(); string path = nameof(viewModel.Command); string parameterPath = nameof(viewModel.Id); object parameterSource = new ViewModel(); textCell.BindCommand(path, source, parameterPath, parameterSource); BindingHelpers.AssertBindingExists(textCell, TextCell.CommandProperty, path, source: source); BindingHelpers.AssertBindingExists(textCell, TextCell.CommandParameterProperty, parameterPath, source: parameterSource); });
public void BindDefaultPropertyWithInlineOneWayParameterizedConvertAndDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind( nameof(viewModel.Text), convert: (string text, int repeat) => string.Concat(Enumerable.Repeat($"'{text?.Trim('\'')}'", repeat)) ); BindingHelpers.AssertBindingExists( label, Label.TextProperty, nameof(viewModel.Text), assertConverterInstanceIsAnyNotNull: true, assertConvert: c => c.AssertConvert("test", 2, "'test''test'") ); });
public void BindDefaultPropertyWithInlineOneWayConvertAndDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind( nameof(viewModel.Text), convert: (string text) => $"'{text}'" ); BindingHelpers.AssertBindingExists( label, Label.TextProperty, nameof(viewModel.Text), assertConverterInstanceIsAnyNotNull: true, assertConvert: c => c.AssertConvert("test", "'test'") ); });
public void BindSpecifiedPropertyWithInlineOneWayConvertAndDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind( Label.TextColorProperty, nameof(viewModel.IsRed), convert: (bool isRed) => isRed ? Color.Red : Color.Transparent ); BindingHelpers.AssertBindingExists( label, Label.TextColorProperty, nameof(viewModel.IsRed), assertConverterInstanceIsAnyNotNull: true, assertConvert: c => c.AssertConvert(true, Color.Red).AssertConvert(false, Color.Transparent) ); });
public void BindSpecifiedPropertyWithInlineOneWayParameterizedConvertAndDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind( Label.TextColorProperty, nameof(viewModel.IsRed), convert: (bool isRed, double alpha) => (isRed ? Color.Red : Color.Green).MultiplyAlpha(alpha) ); BindingHelpers.AssertBindingExists( label, Label.TextColorProperty, nameof(viewModel.IsRed), assertConverterInstanceIsAnyNotNull: true, assertConvert: c => c.AssertConvert(true, 0.5, Color.Red.MultiplyAlpha(0.5)) .AssertConvert(false, 0.2, Color.Green.MultiplyAlpha(0.2)) ); });
public void BindDefaultPropertyWithInlineTwoWayConvertAndDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind( nameof(viewModel.Text), BindingMode.TwoWay, (string text) => $"'{text?.Trim('\'')}'", text => text?.Trim('\'') ); BindingHelpers.AssertBindingExists( label, Label.TextProperty, nameof(viewModel.Text), BindingMode.TwoWay, assertConverterInstanceIsAnyNotNull: true, assertConvert: c => c.AssertConvert("test", "'test'", twoWay: true) ); });
public void BindSpecifiedPropertyWithInlineTwoWayConvertAndPositionalParameters() => AssertExperimental(() => { var button = new Button(); object converterParameter = 1; string stringFormat = nameof(BindSpecifiedPropertyWithInlineTwoWayConvertAndPositionalParameters) + " {0}"; object source = new ViewModel(); object targetNullValue = nameof(BindSpecifiedPropertyWithInlineTwoWayConvertAndPositionalParameters) + " null"; object fallbackValue = nameof(BindSpecifiedPropertyWithInlineTwoWayConvertAndPositionalParameters) + " fallback"; button.Bind( Button.TextProperty, nameof(viewModel.Text), BindingMode.TwoWay, (string text) => $"'{text?.Trim('\'')}'", text => text?.Trim('\''), converterParameter, stringFormat, source, targetNullValue, fallbackValue ); BindingHelpers.AssertBindingExists( button, targetProperty: Button.TextProperty, path: nameof(viewModel.Text), mode: BindingMode.TwoWay, assertConverterInstanceIsAnyNotNull: true, converterParameter: converterParameter, stringFormat: stringFormat, source: source, targetNullValue: targetNullValue, fallbackValue: fallbackValue, assertConvert: c => c.AssertConvert("test", "'test'", twoWay: true) ); });
public void BindSpecifiedPropertyWithDefaults() => AssertExperimental(() => { var label = new Label(); label.Bind(Label.TextColorProperty, nameof(viewModel.TextColor)); BindingHelpers.AssertBindingExists(label, Label.TextColorProperty, nameof(viewModel.TextColor)); });