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);
        }
示例#2
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));
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
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);
        }