private PpsGenericWpfControl UpdateControl(object args)
        {
            PpsGenericWpfControl returnValue;

            if (args is PpsGenericWpfControl paneControl)             // force a framework element
            {
                returnValue = paneControl;
            }
            else if (args is LuaTable t)             // should be properties for the PpsGenericWpfControl
            {
                var creator = LuaWpfCreator.CreateFactory(ShellWpf.LuaUI, typeof(PpsGenericWpfControl));
                creator.SetTableMembers(t);
                using (var xamlReader = new PpsXamlReader(creator.CreateReader(this), new PpsXamlReaderSettings()
                {
                    Code = this, CloseInput = true, BaseUri = Request.BaseAddress, ServiceProvider = this
                }))
                    returnValue = PpsXamlParser.LoadAsync <PpsGenericWpfControl>(xamlReader).AwaitTask();
            }
            else
            {
                throw new ArgumentException(nameof(args));
            }

            Control = returnValue;
            OnControlCreated();

            return(Control);
        }         // proc UpdateControl
 private object LuaCreateCrontrol(LuaWpfCreator control, LuaTable services)
 => control.GetInstanceAsync <object>(this,
                                      new PpsXamlReaderSettings()
 {
     Code            = this,
     ServiceProvider = this,
     ParserServices  = services.ArrayList.Cast <PpsParserService>().ToArray()
 }
                                      ).AwaitTask();
Ejemplo n.º 3
0
        private static LuaWpfCreator CreateComboField(IPpsDataFieldReadOnlyProperties properties)
        {
            dynamic ui = new LuaUI();
            //dynamic combo = LuaWpfCreator.CreateFactory(ui, typeof(ComboBox));
            dynamic combo = LuaWpfCreator.CreateFactory(ui, typeof(PpsComboBox));

            combo.SelectedValue = PpsDataFieldBinding.CreateWpfBinding(properties.GetService <PpsDataFieldInfo>(true));

            return(combo);
        }         // func CreateComboField
Ejemplo n.º 4
0
        private LuaWpfCreator CreateCheckField(IPpsDataFieldReadOnlyProperties properties)
        {
            dynamic ui    = new LuaUI();
            dynamic check = LuaWpfCreator.CreateFactory(ui, typeof(CheckBox));

            //check.Content = properties.displayName;
            check.IsThreeState = false;
            check.IsChecked    = PpsDataFieldBinding.CreateWpfBinding(properties.GetService <PpsDataFieldInfo>(true));

            return(check);
        }         // func CreateCheckField
Ejemplo n.º 5
0
        }         // func CreateTextField

        private LuaWpfCreator CreateSelector(IPpsDataFieldReadOnlyProperties properties)
        {
            dynamic combobox = LuaWpfCreator.CreateFactory(new LuaUI(), typeof(PpsComboBox));

            if (properties.TryGetProperty <bool>("Nullable", out var tmpNullable))
            {
                combobox.IsNullable = tmpNullable;
            }

            SetTextFieldProperties((object)combobox, properties);

            return(combobox);
        }         // func CreateSelector
Ejemplo n.º 6
0
        }         // func CreateField

        private bool TryResolveFieldCreator(IPpsDataFieldReadOnlyProperties properties, out LuaWpfCreator[] creator)
        {
            if (String.IsNullOrEmpty(properties.UseFieldFactory))
            {
                creator = null;
                return(false);
            }

            // resolve complex fieldinformation within the Environment
            // the member must be registered within the table.
            var result = new LuaResult(CallMemberDirect(properties.UseFieldFactory, new object[] { properties }, rawGet: true, throwExceptions: true, ignoreNilFunction: true));

            if (result.Count == 0)
            {
                creator = null;
                return(false);
            }
            else if (result.Count == 1 && result[0] is LuaWpfCreator r)
            {
                creator = new LuaWpfCreator[] { r };
                return(true);
            }
            else if (result.Count == 1 && result[0] is LuaWpfCreator[] ra)
            {
                creator = ra;
                return(true);
            }
            else if (result.Count > 1)
            {
                var wpfControls = new LuaWpfCreator[result.Count];
                for (var i = 0; i < wpfControls.Length; i++)
                {
                    if (result[i] is LuaWpfCreator t)
                    {
                        wpfControls[i] = t;
                    }
                    else
                    {
                        throw new ArgumentNullException(properties.UseFieldFactory, "Return type must be a control creator.");
                    }
                }
                creator = wpfControls;
                return(true);
            }
            else
            {
                throw new ArgumentNullException(properties.UseFieldFactory, "Return type must be a control creator.");
            }
        }         // func TryResolveFieldCreator
Ejemplo n.º 7
0
        }         // ctor

        /// <summary></summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        public System.Xaml.XamlReader CreateField(IPpsDataFieldReadOnlyProperties properties)
        {
            // create controls
            if (!TryResolveFieldCreator(properties, out var controls))
            {
                var ctrl = CreateDefaultField(properties);

                // update display name
                if (ctrl[PpsDataFieldPanel.LabelProperty] == null &&
                    properties.TryGetProperty <string>("displayName", out var displayName) &&
                    !String.IsNullOrEmpty(displayName))
                {
                    ctrl[PpsDataFieldPanel.LabelProperty] = displayName + ":";
                }

                controls = new LuaWpfCreator[] { ctrl };
            }

            // update local properties
            if (controls != null && controls.Length > 0)
            {
                foreach (var p in properties.LocalProperties())
                {
                    foreach (var c in controls)
                    {
                        c[p.Property] = p.Value;
                    }
                }
            }

            // emit code
            if (controls == null || controls.Length == 0)
            {
                return(null);
            }
            else if (controls.Length == 1)
            {
                return(controls[0].CreateReader(properties.Context));
            }
            else
            {
                return(LuaWpfCreator.CreateCollectionReader(from c in controls select c.CreateReader(properties.Context)));
            }
        }         // func CreateField
Ejemplo n.º 8
0
        private LuaWpfCreator CreateRelationField(IPpsDataFieldReadOnlyProperties properties, PpsDataColumnDefinition columnDefinition)
        {
            dynamic combobox = CreateSelector(properties);

            // bind items source
            if (!properties.TryGetProperty <string>("TableBindingPath", out var baseBindingPath))
            {
                baseBindingPath = properties.GetService <PpsDataSetResolver>(true).BindingPath;
            }

            var codeBase = properties.GetService <IPpsXamlCode>(true);

            dynamic itemsSourceBinding = LuaWpfCreator.CreateFactory(new LuaUI(), typeof(Binding));

            itemsSourceBinding.Path   = PpsDataFieldBinding.CombinePath(baseBindingPath, columnDefinition.ParentColumn.Table.Name);
            itemsSourceBinding.Source = codeBase;
            combobox.ItemsSource      = itemsSourceBinding;

            // bind value
            combobox.SelectedValue = PpsDataFieldBinding.CreateWpfBinding(properties.GetService <PpsDataFieldInfo>(true));

            return(combobox);
        }         // func CreateRelationField
Ejemplo n.º 9
0
        private LuaWpfCreator CreateTextField(IPpsDataFieldReadOnlyProperties properties, bool formattedText = false)
        {
            var     ui  = new LuaUI();
            dynamic txt = LuaWpfCreator.CreateFactory(ui, typeof(PpsTextBox));

            var isReadOnly = properties.TryGetProperty <bool>("IsReadOnly", out var tmpReadOnly) ? (bool?)tmpReadOnly : null;

            var textBinding = PpsDataFieldBinding.CreateWpfBinding(properties.GetService <PpsDataFieldInfo>(true), append: formattedText ? "Value" : null, isReadOnly: isReadOnly);

            var inputType    = formattedText ? PpsTextBoxInputType.MultiLine : PpsTextBoxInputType.None;
            var setMaxLength = true;

            switch (Type.GetTypeCode(properties.DataType))
            {
            case TypeCode.Decimal:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 2);
                inputType    = PpsTextBoxInputType.DecimalNegative;
                setMaxLength = false;
                break;

            case TypeCode.Single:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 3);
                inputType    = PpsTextBoxInputType.DecimalNegative;
                setMaxLength = false;
                break;

            case TypeCode.Double:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 6);
                inputType    = PpsTextBoxInputType.DecimalNegative;
                setMaxLength = false;
                break;

            case TypeCode.SByte:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 0);
                inputType = PpsTextBoxInputType.IntegerNegative;
                break;

            case TypeCode.Int16:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 0);
                inputType = PpsTextBoxInputType.IntegerNegative;
                break;

            case TypeCode.Int32:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 0);
                inputType = PpsTextBoxInputType.IntegerNegative;
                break;

            case TypeCode.Int64:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, true, 0);
                inputType = PpsTextBoxInputType.IntegerNegative;
                break;

            case TypeCode.Byte:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, false, 0);
                inputType = PpsTextBoxInputType.Integer;
                break;

            case TypeCode.UInt16:
                SetNumericBinding(ui, txt, textBinding, false, 0);
                inputType = PpsTextBoxInputType.Integer;
                break;

            case TypeCode.UInt32:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, false, 0);
                inputType = PpsTextBoxInputType.Integer;
                break;

            case TypeCode.UInt64:
                PpsDataFieldFactory.SetNumericBinding(ui, txt, textBinding, false, 0);
                inputType = PpsTextBoxInputType.Integer;
                break;

            case TypeCode.DateTime:
                if (inputType != PpsTextBoxInputType.Date &&
                    inputType != PpsTextBoxInputType.Time)
                {
                    inputType = PpsTextBoxInputType.Date;
                }

                if (inputType == PpsTextBoxInputType.Date)                         // we can set a binding converter
                {
                    PpsDataFieldFactory.SetDateBinding(ui, txt, textBinding, false, 0);
                }
                break;
            }

            if (properties.TryGetProperty <PpsTextBoxInputType>("InputType", out var tmpInputType))
            {
                inputType = tmpInputType;
            }

            txt.InputType = inputType;
            txt.Text      = textBinding;

            SetTextFieldProperties((object)txt, properties);

            if (setMaxLength && properties.TryGetProperty <int>("MaxLength", out var maxInputLength))
            {
                txt.MaxLength = maxInputLength;
            }

            if (properties.TryGetProperty <bool>("Nullable", out var tmpNullable))
            {
                txt.IsNullable = tmpNullable;
            }

            if (isReadOnly.HasValue)
            {
                txt.IsReadOnly = isReadOnly;
            }

            if (formattedText)
            {
                txt.FormattedValue = PpsDataFieldBinding.CreateWpfBinding(properties.GetService <PpsDataFieldInfo>(true), append: "FormattedValue", isReadOnly: true);
            }

            return(txt);
        }         // func CreateTextField