示例#1
0
        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
                );
        });
示例#2
0
        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)
                );
        });
示例#3
0
        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'")
                );
        });
示例#4
0
        public void BindTapGestureDefaults() => AssertExperimental(() =>
        {
            var gestureElement = new TGestureElement();

            gestureElement.BindTapGesture(commandPath);

            var gestureRecognizer = AssertHasGestureRecognizer <TapGestureRecognizer>(gestureElement);
            BindingHelpers.AssertBindingExists(gestureRecognizer, TapGestureRecognizer.CommandProperty, commandPath);
        });
示例#5
0
        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);
        });
示例#6
0
        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);
        });
示例#7
0
        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);
        });
示例#8
0
        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);
        });
示例#9
0
        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'")
                );
        });
示例#10
0
        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'")
                );
        });
示例#11
0
        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)
                );
        });
示例#12
0
        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))
                );
        });
示例#13
0
        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)
                );
        });
示例#14
0
        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)
                );
        });
示例#15
0
 public void BindSpecifiedPropertyWithDefaults() => AssertExperimental(() =>
 {
     var label = new Label();
     label.Bind(Label.TextColorProperty, nameof(viewModel.TextColor));
     BindingHelpers.AssertBindingExists(label, Label.TextColorProperty, nameof(viewModel.TextColor));
 });