Пример #1
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiListBox));

            _vertical = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Vertical) == Mode.Vertical;

            _template = (DefinitionFile)file["Template"];

            _items = (IItemsProvider)DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["Items"]);
            _items.Subscribe(this);

            _rule = DefinitionResolver.Get <ScrollingService.ExceedRule>(Controller, Binding, file["ExceedRule"], ScrollingService.ExceedRule.Allow);

            _maxScrollExceed = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxScrollExceed"], ScrollingService.MaxScrollExceed);

            _reverse = DefinitionResolver.Get <bool>(Controller, Binding, file["Reverse"], false);

            _wheelSpeed = (float)DefinitionResolver.Get <double>(Controller, Binding, file["WheelScrollSpeed"], 0);

            _additionalTemplates = file["AdditionalTemplates"] as Dictionary <Type, DefinitionFile>;

            _maxAddOneTime   = DefinitionResolver.Get <int>(Controller, Binding, file["MaxAddOneTime"], 32);
            _maxAddFirstTime = DefinitionResolver.Get <int>(Controller, Binding, file["MaxAddFirstTime"], _maxAddOneTime);

            return(true);
        }
Пример #2
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiQuickList));

            _items = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["Items"]) as IItemsProvider;

            if (_items == null)
            {
                return(false);
            }

            _items.Subscribe(this);

            _rowHeight       = DefinitionResolver.Get <Length>(Controller, Binding, file["RowHeight"], Length.Default);
            _separatorHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["SeparatorHeight"], Length.Zero);

            _maxScrollExceed = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxScrollExceed"], ScrollingService.MaxScrollExceed);
            _reversed        = DefinitionResolver.Get <bool>(Controller, Binding, file["Reversed"], false);

            _wheelSpeed = (float)DefinitionResolver.Get <double>(Controller, Binding, file["WheelScrollSpeed"], 0);
            _rule       = DefinitionResolver.Get <ScrollingService.ExceedRule>(Controller, Binding, file["ExceedRule"], ScrollingService.ExceedRule.Allow);

            _columns = new List <QuickColumnDefinition>();

            List <DefinitionFile> columnsDef = file["Columns"] as List <DefinitionFile>;

            if (columnsDef == null)
            {
                throw new Exception("Columns not defined!");
            }

            foreach (var cd in columnsDef)
            {
                QuickColumnDefinition columnDefinitionObj = cd.CreateInstance(Controller, Binding) as QuickColumnDefinition;
                _columns.Add(columnDefinitionObj);
            }

            DefinitionFile separatorDef = file["Separator"] as DefinitionFile;

            if (separatorDef != null)
            {
                _separator = separatorDef.CreateInstance(Controller, Binding) as QuickSeparator;
            }

            return(true);
        }
Пример #3
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiIndexSelector));

            var context = file["Context"];

            if ((context is MethodName) || (context is FieldName))
            {
                var obj = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, context);

                if (obj is IIndexedElement)
                {
                    _element = obj as IIndexedElement;
                }
                else if (obj is string)
                {
                    _context = obj as string;
                }
            }
            else
            {
                _context = DefinitionResolver.GetString(Controller, Binding, context);
            }

            if (_element == null)
            {
                _element = Controller.Find(_context) as IIndexedElement;
            }

            _spacing  = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero);
            _vertical = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical;

            _elementWidth  = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementWidth"], Length.Stretch);
            _elementHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementHeight"], Length.Stretch);

            _contentHorizontalAlignment = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center);
            _contentVerticalAlignment   = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center);

            return(true);
        }
Пример #4
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiItemsStack));

            _template = (DefinitionFile)file["Template"];

            _additionalTemplates = file["AdditionalTemplates"] as Dictionary <Type, DefinitionFile>;

            _items = (IItemsProvider)DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["Items"]);
            _items.Subscribe(this);

            return(true);
        }
Пример #5
0
        protected override bool Init(object controller, object binding, DefinitionFiles.DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiScrollingSelector));

            _context = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["Context"]) as ISelectorContext;

            _elementHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementHeight"], Length.Zero);
            _spacing       = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero);

            _autoValidate = DefinitionResolver.Get <bool>(Controller, Binding, file["AutoValidate"], false);

            _selectedPositionOffset = DefinitionResolver.Get <Length>(Controller, Binding, file["SelectedPositionOffset"], Length.Zero);

            List <DefinitionFile> drawableFiles = file["Drawables"] as List <DefinitionFile>;

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _drawables.Add(drawable);
                    }
                }
            }

            EnabledGestures = GestureType.Tap | GestureType.Up | GestureType.Down | GestureType.VerticalDrag;

            return(true);
        }
Пример #6
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            TryInitChildren(definition);

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiContentSlider));

            if (file["SelectedIndex"] is MethodName || file["SelectedIndex"] is FieldName)
            {
                object value = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["SelectedIndex"]);

                if (value is SharedValue <int> )
                {
                    _sharedSelectedIndex = value as SharedValue <int>;
                    _selectedIndex       = _sharedSelectedIndex.Value;
                }

                if (value is int)
                {
                    _selectedIndex = (int)value;
                }
            }
            else
            {
                _selectedIndex = DefinitionResolver.Get <int>(Controller, Binding, file["SelectedIndex"], 0);
            }

            _cycle = DefinitionResolver.Get <bool>(Controller, Binding, file["Cycle"], false);

            double speed = DefinitionResolver.Get <double>(Controller, Binding, file["TransitionTime"], 500) / 1000.0;

            _transitionSpeed = (float)(speed > 0 ? 1 / speed : float.MaxValue);

            DefinitionFile transitionEffectFile = file["ShowTransitionEffectNext"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                _transitionEffectShowNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            transitionEffectFile = file["HideTransitionEffectNext"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                _transitionEffectHideNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            transitionEffectFile = file["ShowTransitionEffectPrev"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                _transitionEffectShowPrev = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            transitionEffectFile = file["HideTransitionEffectPrev"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                _transitionEffectHidePrev = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            transitionEffectFile = file["ShowTransitionEffect"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                if (_transitionEffectShowPrev == null)
                {
                    _transitionEffectShowPrev = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }

                if (_transitionEffectShowNext == null)
                {
                    _transitionEffectShowNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            transitionEffectFile = file["HideTransitionEffect"] as DefinitionFile;

            if (transitionEffectFile != null)
            {
                if (_transitionEffectHidePrev == null)
                {
                    _transitionEffectHidePrev = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }

                if (_transitionEffectHideNext == null)
                {
                    _transitionEffectHideNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            if (_transitionEffectHideNext == null)
            {
                if (_transitionEffectShowNext != null)
                {
                    _transitionEffectHideNext = _transitionEffectShowNext.Reverse();
                }
            }

            if (_transitionEffectHidePrev == null)
            {
                if (_transitionEffectShowPrev != null)
                {
                    _transitionEffectHidePrev = _transitionEffectShowPrev.Reverse();
                }
            }

            if (_children.Count > 0)
            {
                _current = _children[_selectedIndex];
            }

            _previous = null;

            return(true);
        }
Пример #7
0
        protected virtual bool Init(object controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiView));

            Type controllerType = file["Controller"] as Type;

            _controller = controller as UiController;

            if (controllerType != null)
            {
                var newController = Activator.CreateInstance(controllerType) as UiController;

                if (newController != null)
                {
                    newController.Parent = _controller;
                    Controller           = newController;
                }
            }

            Binding = binding;

            object bindParameter = file["Binding"];

            if (bindParameter != null)
            {
                Object bind = DefinitionResolver.GetValueFromMethodOrField(Controller, binding, bindParameter);

                if (bind != null)
                {
                    Binding = bind;
                }
            }

            Id = DefinitionResolver.GetString(Controller, Binding, file["Id"]);

            if (file["Hidden"] != null && file["Visible"] == null)
            {
                _visiblityFlag   = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Hidden"], false);
                _visibleIsHidden = true;
            }
            else
            {
                _visiblityFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Visible"], true);
            }

            Tag = DefinitionResolver.GetSharedString(Controller, Binding, file["Tag"]);

            Opacity = DefinitionResolver.GetShared <double>(Controller, Binding, file["Opacity"], 1);

            DisplayVisibility = Visible ? 1 : 0;

            _modal = DefinitionResolver.Get <bool>(Controller, Binding, file["Modal"], false);

            RegisterDelegate("ViewRemoved", file["ViewRemoved"]);
            RegisterDelegate("ViewAdded", file["ViewAdded"]);
            RegisterDelegate("ViewActivated", file["ViewActivated"]);
            RegisterDelegate("ViewDeactivated", file["ViewDeactivated"]);
            RegisterDelegate("ViewResized", file["ViewResized"]);

            _minWidth  = DefinitionResolver.Get <Length>(Controller, Binding, file["MinWidth"], Length.Zero);
            _minHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["MinHeight"], Length.Zero);

            _showSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowTime"], -1));

            if (_showSpeed < 0)
            {
                _showSpeed = DefaultShowTime;
            }

            _showSpeed /= 1000.0f;

            _showSpeed = _showSpeed > 0 ? 1 / _showSpeed : float.MaxValue;

            _hideSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["HideTime"], -1));

            if (_hideSpeed < 0)
            {
                _hideSpeed = DefaultHideTime;
            }

            _hideSpeed /= 1000.0f;

            _hideSpeed = _hideSpeed > 0 ? 1 / _hideSpeed : float.MaxValue;

            CreatePositionParameters(Controller, Binding, definition);

            DefinitionFile backgroundDrawable = file["BackgroundDrawable"] as DefinitionFile;

            Color defaultBackgroundColor = Color.Transparent;

            if (backgroundDrawable != null)
            {
                BackgroundDrawable = backgroundDrawable.CreateInstance(Controller, Binding) as IBackgroundDrawable;

                if (BackgroundDrawable != null)
                {
                    defaultBackgroundColor = Color.White;
                }
            }

            _backgroundColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["BackgroundColor"]) ?? new ColorWrapper(defaultBackgroundColor);

            DefinitionFile showTransitionEffectFile       = file["ShowTransitionEffect"] as DefinitionFile;
            DefinitionFile hideTransitionEffectFile       = file["HideTransitionEffect"] as DefinitionFile;
            DefinitionFile parentShowTransitionEffectFile = file["ParentShowTransitionEffect"] as DefinitionFile;
            DefinitionFile parentHideTransitionEffectFile = file["ParentHideTransitionEffect"] as DefinitionFile;

            if (showTransitionEffectFile != null)
            {
                _showTransitionEffect = showTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (hideTransitionEffectFile != null)
            {
                _hideTransitionEffect = hideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentShowTransitionEffectFile != null)
            {
                _parentShowTransitionEffect = parentShowTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentHideTransitionEffectFile != null)
            {
                _parentHideTransitionEffect = parentHideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            return(true);
        }