public void ScalarCompositeBinding()
        {
            var dataSet = DataSetMock.ProductCategories(1);
            var _       = dataSet._;
            ScalarBinding <Label>             label     = null;
            ScalarBinding <TextBlock>         textBlock = null;
            ScalarCompositeBinding <XamlPane> pane      = null;
            var elementManager = dataSet.CreateElementManager(builder =>
            {
                textBlock = _.Name.AsScalarTextBlock();
                label     = _.Name.AsScalarLabel(textBlock);
                pane      = new ScalarCompositeBinding <XamlPane>().AddChild(label, v => v.Label).AddChild(textBlock, v => v.TextBlock);
                builder.Layout(Orientation.Vertical, 0)
                .GridColumns("100").GridRows("100", "100")
                .AddBinding(0, 0, pane)
                .AddBinding(0, 1, _.Name.BindToTextBlock());
            });

            Assert.IsNull(label.GetSettingUpElement(0));
            Assert.IsNull(textBlock.GetSettingUpElement(0));

            Assert.AreEqual(1, label.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, label[0].Content);
            Assert.AreEqual(1, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(textBlock[0], label[0].Target);
        }
Example #2
0
 internal void Refresh(T v, ScalarPresenter p)
 {
     if (!IsFlushing && !IsLockedByFlushingError(v))
     {
         ScalarBinding.Refresh(v, p);
     }
     v.RefreshValidation(GetValidationInfo(p.FlowIndex));
 }
Example #3
0
 /// <summary>
 /// Adds behavior to scalar binding.
 /// </summary>
 /// <typeparam name="T">Element type of row binding.</typeparam>
 /// <param name="scalarBinding">The scalar binding.</param>
 /// <param name="behavior">The behavior.</param>
 /// <returns>The scalar binding for fluent coding.</returns>
 public static ScalarBinding <T> AddBehavior <T>(this ScalarBinding <T> scalarBinding, IScalarBindingBehavior <T> behavior)
     where T : UIElement, new()
 {
     if (behavior == null)
     {
         throw new ArgumentNullException(nameof(behavior));
     }
     scalarBinding.InternalAddBehavior(behavior);
     return(scalarBinding);
 }
        /// <summary>
        /// Merges editor scalar binding into <see cref="InPlaceEditor"/>, with inert element displays as string.
        /// </summary>
        /// <typeparam name="T">The element type of editor scalar binding.</typeparam>
        /// <param name="editorScalarBinding">The editor scalar binding.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
        /// <returns>The scalar binding object of <see cref="InPlaceEditor"/>.</returns>
        public static ScalarBinding <InPlaceEditor> MergeIntoInPlaceEditor <T>(this ScalarBinding <T> editorScalarBinding, string format = null, IFormatProvider formatProvider = null)
            where T : UIElement, new()
        {
            var scalarInput = VerifyEditorBinding(editorScalarBinding, nameof(editorScalarBinding));

            if (!(scalarInput.Target is Scalar scalar))
            {
                throw new ArgumentException(DiagnosticMessages.InPlaceEditor_EditorScalarBindingNotScalar, nameof(editorScalarBinding));
            }
            var inertScalarBinding = scalar.BindToTextBlock(format, formatProvider);

            return(MergeIntoInPlaceEditor(scalarInput, inertScalarBinding));
        }
        private static ScalarInput <T> VerifyEditorBinding <T>(ScalarBinding <T> editorScalarBinding, string paramName)
            where T : UIElement, new()
        {
            if (editorScalarBinding == null)
            {
                throw new ArgumentNullException(paramName);
            }
            var scalarInput = editorScalarBinding.Input;

            if (scalarInput == null)
            {
                throw new ArgumentException(DiagnosticMessages.InPlaceEditor_VerifyEditorBinding, paramName);
            }
            return(scalarInput);
        }
Example #6
0
        /// <summary>
        /// Adds child binding.
        /// </summary>
        /// <typeparam name="TChild">Type of child view element.</typeparam>
        /// <param name="childBinding">The child binding.</param>
        /// <param name="childGetter">Getter to return child view element.</param>
        /// <returns>This scalar composite binding for fluent coding.</returns>
        public ScalarCompositeBinding <T> AddChild <TChild>(ScalarBinding <TChild> childBinding, Func <T, TChild> childGetter)
            where TChild : UIElement, new()
        {
            Binding.VerifyAdding(childBinding, nameof(childBinding));

            if (childGetter == null)
            {
                throw new ArgumentNullException(nameof(childGetter));
            }

            VerifyNotSealed();
            _childBindings.Add(childBinding);
            _childGetters.Add(childGetter);
            childBinding.Seal(this, _childBindings.Count - 1);
            return(this);
        }
        private static IScalars GetTargetScalars(IScalars result, ScalarBinding binding)
        {
            Debug.Assert(binding != null);
            var input = binding.ScalarInput;

            if (input != null)
            {
                return(result.Union(input.Target));
            }
            var childBindings = binding.ChildBindings;

            if (childBindings == null)
            {
                return(result);
            }
            for (int i = 0; i < childBindings.Count; i++)
            {
                result = GetTargetScalars(result, childBindings[i]);
            }
            return(result);
        }
Example #8
0
        public void ScalarBinding()
        {
            var dataSet = DataSetMock.ProductCategories(1);
            var _       = dataSet._;
            ScalarBinding <Label>     label     = null;
            ScalarBinding <TextBlock> textBlock = null;
            var elementManager = dataSet.CreateElementManager(builder =>
            {
                textBlock = _.Name.AsScalarTextBlock();
                label     = _.Name.AsScalarLabel(textBlock);
                builder.GridColumns("100", "100", "100").GridRows("100").RowRange(2, 0, 2, 0)
                .AddBinding(0, 0, label)
                .AddBinding(1, 0, textBlock);
            });

            Assert.IsNull(label.GetSettingUpElement(0));
            Assert.IsNull(textBlock.GetSettingUpElement(0));

            Assert.AreEqual(1, label.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, label[0].Content);
            Assert.AreEqual(1, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(textBlock[0], label[0].Target);
        }
        /// <summary>
        /// Binds collection of <see cref="ScalarBinding"/> to <see cref="ValidationPlaceholder"/>.
        /// </summary>
        /// <param name="source">The source bindings.</param>
        /// <returns>The scalar binding object.</returns>
        public static ScalarBinding <ValidationPlaceholder> BindToValidationPlaceholder(this IReadOnlyList <ScalarBinding> source)
        {
            source.VerifyNotNull(nameof(source));

            var scalars = GetTargetScalars(source);
            var input   = new ScalarBinding <ValidationPlaceholder>(onSetup: (v, p) =>
            {
                var containingElements = new UIElement[source.Count];
                for (int i = 0; i < containingElements.Length; i++)
                {
                    containingElements[i] = source[i].GetSettingUpElement();
                }
                v.Setup(containingElements);
            }, onRefresh: null, onCleanup: (v, p) =>
            {
                v.Cleanup();
            }).BeginInput(new ExplicitTrigger <ValidationPlaceholder>());

            foreach (var scalar in scalars)
            {
                input.WithFlush(scalar, v => true);
            }
            return(input.EndInput());
        }
Example #10
0
        /// <summary>
        /// Binds the string to <see cref="Label"/>, with specified target scalar binding.
        /// </summary>
        /// <typeparam name="TTarget">The element type of target scalar binding.</typeparam>
        /// <param name="source">The source string.</param>
        /// <param name="target">The target scalar binding.</param>
        /// <returns>The scalar binding object.</returns>
        public static ScalarBinding <Label> BindToLabel <TTarget>(this string source, ScalarBinding <TTarget> target)
            where TTarget : UIElement, new()
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new ScalarBinding <Label>(
                       onSetup: (v, p) =>
            {
                v.Content = source;
                v.Target = target.GetSettingUpElement(p);
            },
                       onRefresh: null, onCleanup: null));
        }
Example #11
0
 /// <summary>
 /// Returns the operation that set initial focus to explicit scalar binding.
 /// </summary>
 /// <param name="binding">The scalar binding.</param>
 /// <returns>The result <see cref="InitialFocus"/>.</returns>
 public static InitialFocus Explicit(ScalarBinding binding)
 {
     binding.VerifyNotNull(nameof(binding));
     return(new MoveToScalarBinding(binding));
 }
Example #12
0
 public MoveToScalarBinding(ScalarBinding binding)
 {
     Debug.Assert(binding != null);
     _binding = binding;
 }
        public void CompositeScalarBinding_flowable()
        {
            var dataSet = DataSetMock.ProductCategories(1);
            var _       = dataSet._;
            ScalarBinding <Label>             label     = null;
            ScalarBinding <TextBlock>         textBlock = null;
            ScalarCompositeBinding <XamlPane> pane      = null;
            var elementManager = dataSet.CreateElementManager(builder =>
            {
                textBlock = _.Name.AsScalarTextBlock();
                label     = _.Name.AsFlowRepeatableScalarLabel(textBlock);
                pane      = new ScalarCompositeBinding <XamlPane>().RepeatWhenFlow()
                            .AddChild(label, v => v.Label).AddChild(textBlock, v => v.TextBlock);
                builder.Layout(Orientation.Vertical, 0)
                .GridColumns("100").GridRows("100", "100")
                .AddBinding(0, 0, pane)
                .AddBinding(0, 1, _.Name.BindToTextBlock());
            });

            Assert.AreEqual(1, pane.FlowRepeatCount);
            Assert.AreEqual(0, pane[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(pane[0].Children[0], label[0]);
            Assert.AreEqual(pane[0].Children[1], textBlock[0]);

            elementManager.FlowRepeatCount = 2;
            Assert.AreEqual(2, pane.FlowRepeatCount);
            Assert.AreEqual(0, pane[0].GetScalarFlowIndex());
            Assert.AreEqual(1, pane[1].GetScalarFlowIndex());
            Assert.AreEqual(2, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);
            Assert.AreEqual(pane[0].Children[0], label[0]);
            Assert.AreEqual(pane[0].Children[1], textBlock[0]);
            Assert.AreEqual(pane[1].Children[0], label[1]);
            Assert.AreEqual(pane[1].Children[1], textBlock[1]);

            elementManager.FlowRepeatCount = 3;
            Assert.AreEqual(3, pane.FlowRepeatCount);
            Assert.AreEqual(0, pane[0].GetScalarFlowIndex());
            Assert.AreEqual(1, pane[1].GetScalarFlowIndex());
            Assert.AreEqual(2, pane[2].GetScalarFlowIndex());
            Assert.AreEqual(3, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual("2. " + _.Name.DisplayName, label[2].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, label[2].GetScalarFlowIndex());
            Assert.AreEqual(3, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[2].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock[2].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);
            Assert.AreEqual(textBlock[2], label[2].Target);
            Assert.AreEqual(pane[0].Children[0], label[0]);
            Assert.AreEqual(pane[0].Children[1], textBlock[0]);
            Assert.AreEqual(pane[1].Children[0], label[1]);
            Assert.AreEqual(pane[1].Children[1], textBlock[1]);
            Assert.AreEqual(pane[2].Children[0], label[2]);
            Assert.AreEqual(pane[2].Children[1], textBlock[2]);

            elementManager.FlowRepeatCount = 2;
            Assert.AreEqual(2, pane.FlowRepeatCount);
            Assert.AreEqual(0, pane[0].GetScalarFlowIndex());
            Assert.AreEqual(1, pane[1].GetScalarFlowIndex());
            Assert.AreEqual(2, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);
            Assert.AreEqual(pane[0].Children[0], label[0]);
            Assert.AreEqual(pane[0].Children[1], textBlock[0]);
            Assert.AreEqual(pane[1].Children[0], label[1]);
            Assert.AreEqual(pane[1].Children[1], textBlock[1]);
        }
Example #14
0
 /// <summary>
 /// Adds scalar binding.
 /// </summary>
 /// <param name="left">Index of left grid column.</param>
 /// <param name="top">Index of top grid row.</param>
 /// <param name="right">Index of right grid column.</param>
 /// <param name="bottom">Index of bottom grid row.</param>
 /// <param name="scalarBinding">The scalar binding.</param>
 /// <returns>This template builder for fluent coding.</returns>
 public TemplateBuilder AddBinding(int left, int top, int right, int bottom, ScalarBinding scalarBinding)
 {
     Binding.VerifyAdding(scalarBinding, nameof(scalarBinding));
     Template.AddBinding(Template.Range(left, top, right, bottom), scalarBinding);
     return(this);
 }
Example #15
0
 /// <summary>
 /// Adds scalar binding.
 /// </summary>
 /// <param name="column">Index of grid column.</param>
 /// <param name="row">Index of grid row.</param>
 /// <param name="scalarBinding">The scalar binding.</param>
 /// <returns>This template builder for fluent coding.</returns>
 public TemplateBuilder AddBinding(int column, int row, ScalarBinding scalarBinding)
 {
     return(AddBinding(column, row, column, row, scalarBinding));
 }
Example #16
0
        public void ScalarBinding_flowable()
        {
            var dataSet = DataSetMock.ProductCategories(1);
            var _       = dataSet._;
            ScalarBinding <Label>     label     = null;
            ScalarBinding <TextBlock> textBlock = null;
            var elementManager = dataSet.CreateElementManager(builder =>
            {
                textBlock = _.Name.AsScalarTextBlock().RepeatWhenFlow();
                label     = _.Name.AsFlowRepeatableScalarLabel(textBlock);
                builder.Layout(Orientation.Vertical, 0)
                .GridColumns("100", "100").GridRows("100", "100")
                .AddBinding(0, 0, label)
                .AddBinding(0, 1, 1, 1, _.Name.BindToTextBlock())
                .AddBinding(1, 0, textBlock);
            });

            elementManager.FlowRepeatCount = 2;

            Assert.IsNull(label.GetSettingUpElement(0));
            Assert.IsNull(textBlock.GetSettingUpElement(0));

            Assert.AreEqual(2, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);

            elementManager.FlowRepeatCount = 3;
            Assert.AreEqual(3, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual("2. " + _.Name.DisplayName, label[2].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, label[2].GetScalarFlowIndex());
            Assert.AreEqual(3, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[2].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock[2].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);
            Assert.AreEqual(textBlock[2], label[2].Target);

            elementManager.FlowRepeatCount = 2;
            Assert.AreEqual(2, label.FlowRepeatCount);
            Assert.AreEqual("0. " + _.Name.DisplayName, label[0].Content);
            Assert.AreEqual("1. " + _.Name.DisplayName, label[1].Content);
            Assert.AreEqual(0, label[0].GetScalarFlowIndex());
            Assert.AreEqual(1, label[1].GetScalarFlowIndex());
            Assert.AreEqual(2, textBlock.FlowRepeatCount);
            Assert.AreEqual(_.Name.DisplayName, textBlock[0].Text);
            Assert.AreEqual(_.Name.DisplayName, textBlock[1].Text);
            Assert.AreEqual(0, textBlock[0].GetScalarFlowIndex());
            Assert.AreEqual(1, textBlock[1].GetScalarFlowIndex());
            Assert.AreEqual(textBlock[0], label[0].Target);
            Assert.AreEqual(textBlock[1], label[1].Target);
        }
Example #17
0
 /// <summary>
 /// Adds scalar binding.
 /// </summary>
 /// <typeparam name="TElement">Type of view element.</typeparam>
 /// <param name="element">The view element.</param>
 /// <param name="scalarBinding">The scalar binding.</param>
 /// <returns>This template builder for fluent coding.</returns>
 public T AddBinding <TElement>(TElement element, ScalarBinding <TElement> scalarBinding)
     where TElement : UIElement, new()
 {
     Template.AddBinding(element, scalarBinding);
     return((T)this);
 }
Example #18
0
        public static ScalarBinding <Label> AsScalarLabel <TTarget>(this Column source, ScalarBinding <TTarget> target = null, string format = null, IFormatProvider formatProvider = null)
            where TTarget : UIElement, new()
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new ScalarBinding <Label>(
                       onSetup: (v, p) =>
            {
                v.Content = source.DisplayName.ToString(format, formatProvider);
                if (target != null)
                {
                    v.Target = target.GetSettingUpElement(p);
                }
            },
                       onRefresh: null,
                       onCleanup: null));
        }
Example #19
0
 internal ScalarInput(ScalarBinding <T> scalarBinding, Trigger <T> flushTrigger, Trigger <T> progressiveFlushTrigger)
     : base(flushTrigger, progressiveFlushTrigger)
 {
     Debug.Assert(scalarBinding != null);
     ScalarBinding = scalarBinding;
 }
        /// <summary>
        /// Merges editor scalar binding into <see cref="InPlaceEditor"/>, with inert scalar binding.
        /// </summary>
        /// <typeparam name="TEditor">The element type of editor scalar binding.</typeparam>
        /// <typeparam name="TInert">The element type of inert scalar binding.</typeparam>
        /// <param name="editorScalarBinding">The editor scalar binding.</param>
        /// <param name="inertScalarBinding">The inert scacalr binding.</param>
        /// <returns>The scalar binding object of <see cref="InPlaceEditor"/>.</returns>
        public static ScalarBinding <InPlaceEditor> MergeIntoInPlaceEditor <TEditor, TInert>(this ScalarBinding <TEditor> editorScalarBinding, ScalarBinding <TInert> inertScalarBinding)
            where TEditor : UIElement, new()
            where TInert : UIElement, new()
        {
            var scalarInput = VerifyEditorBinding(editorScalarBinding, nameof(editorScalarBinding));

            inertScalarBinding.VerifyNotNull(nameof(inertScalarBinding));
            return(MergeIntoInPlaceEditor(scalarInput, inertScalarBinding));
        }
 private static ScalarBinding <InPlaceEditor> MergeIntoInPlaceEditor <TEditing, TInert>(this ScalarInput <TEditing> scalarInput, ScalarBinding <TInert> inertScalarBinding)
     where TEditing : UIElement, new()
     where TInert : UIElement, new()
 {
     Debug.Assert(scalarInput != null);
     Debug.Assert(inertScalarBinding != null);
     return(InPlaceEditor.AddToInPlaceEditor(scalarInput, inertScalarBinding));
 }