Inheritance: ListView, IDisposable
        /// <summary>
        /// Initializes a new instance of the <see cref="DLToolkit.Forms.Controls.FlowListViewInternalCell"/> class.
        /// </summary>
        /// <param name="flowListViewRef">Flow list view reference.</param>
        public FlowListViewInternalCell(WeakReference <FlowListView> flowListViewRef)
        {
            _flowListViewRef = flowListViewRef;
            FlowListView flowListView = null;

            flowListViewRef.TryGetTarget(out flowListView);
            _useGridAsMainRoot = !flowListView.FlowUseAbsoluteLayoutInternally;

            if (!_useGridAsMainRoot)
            {
                _rootLayout = new AbsoluteLayout()
                {
                    Padding         = 0d,
                    BackgroundColor = flowListView.FlowRowBackgroundColor,
                };
                View = _rootLayout;
            }
            else
            {
                _rootLayoutAuto = new Grid()
                {
                    RowSpacing      = 0d,
                    ColumnSpacing   = 0d,
                    Padding         = 0d,
                    BackgroundColor = flowListView.FlowRowBackgroundColor,
                };
                View = _rootLayoutAuto;
            }

            _flowColumnTemplate = flowListView.FlowColumnTemplate;
            _desiredColumnCount = flowListView.DesiredColumnCount;
            _flowColumnExpand   = flowListView.FlowColumnExpand;
        }
		public FlowListViewInternalCell(FlowListView flowListView)
		{
			this.flowListView = flowListView;

			root = new Grid() {
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				RowSpacing = 0f,
				ColumnSpacing = 0f,
				Padding = 0f,
				RowDefinitions = new RowDefinitionCollection() {
					new RowDefinition() { Height = GridLength.Auto }
				},
				ColumnDefinitions = new ColumnDefinitionCollection()
			};

			for (int i = 0; i < this.flowListView.FlowColumnsDefinitions.Count; i++)
			{
				root.ColumnDefinitions.Add(new ColumnDefinition() {
					Width = new GridLength(1, GridUnitType.Star)
				});
			}

			View = root;
		}
Exemple #3
0
        protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
        {
            if (item is FlowLoadingModel)
            {
                FlowListView flowListView = null;
                if (_flowListViewRef.TryGetTarget(out flowListView))
                {
                    return(flowListView.FlowLoadingTemplate);
                }
            }
            else if (item is FlowEmptyModel)
            {
                FlowListView flowListView = null;
                if (_flowListViewRef.TryGetTarget(out flowListView))
                {
                    return(flowListView.FlowEmptyTemplate);
                }
            }

            return(_defaultTemplate);
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DLToolkit.Forms.Controls.FlowListViewInternalCell"/> class.
        /// </summary>
        /// <param name="flowListViewRef">Flow list view reference.</param>
        public FlowListViewInternalCell(WeakReference <FlowListView> flowListViewRef)
        {
            this.flowListViewRef = flowListViewRef;
            FlowListView flowListView = null;

            flowListViewRef.TryGetTarget(out flowListView);

            rootLayout = new AbsoluteLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = 0d,
                BackgroundColor   = flowListView.FlowRowBackgroundColor,
            };

            View = rootLayout;

            flowColumnsTemplates = flowListView.FlowColumnsTemplates;
            desiredColumnCount   = flowListView.DesiredColumnCount;
            flowAutoColumnCount  = flowListView.FlowAutoColumnCount;
            flowColumnExpand     = flowListView.FlowColumnExpand;
        }
        async Task ExecuteTapGestureRecognizer(View view)
        {
            var flowCell = view as IFlowViewCell;

            if (flowCell != null)
            {
                flowCell.OnTapped();
            }

            FlowListView flowListView = null;

            _flowListViewRef.TryGetTarget(out flowListView);

            if (flowListView != null)
            {
                int tapBackgroundEffectDelay = flowListView.FlowTappedBackgroundDelay;

                try
                {
                    if (tapBackgroundEffectDelay != 0)
                    {
                        view.BackgroundColor = flowListView.FlowTappedBackgroundColor;
                    }

                    flowListView.FlowPerformTap(view, view.BindingContext);
                }
                finally
                {
                    if (tapBackgroundEffectDelay != 0)
                    {
                        await Task.Delay(tapBackgroundEffectDelay);

                        view.BackgroundColor = flowListView.FlowRowBackgroundColor;
                    }
                }
            }
        }
        private void UpdateData()
        {
            var container = BindingContext as IList;

            if (container == null)
            {
                return;
            }

            var newDesiredColumnCount = 0;

            FlowListView flowListView = null;

            if (_flowListViewRef.TryGetTarget(out flowListView) && flowListView != null)
            {
                _flowColumnTemplate   = flowListView.FlowColumnTemplate;
                newDesiredColumnCount = flowListView.FlowDesiredColumnCount;
                _flowColumnExpand     = flowListView.FlowColumnExpand;
            }

            var flowGroupColumn = BindingContext as FlowGroupColumn;

            if (flowGroupColumn != null)
            {
                newDesiredColumnCount = flowGroupColumn.ColumnCount;
            }

            // Getting view types from templates
            var containerCount             = container.Count;
            IList <DataTemplate> templates = GetDataTemplates(container);

            bool layoutChanged = false;

            if (flowGroupColumn != null && flowGroupColumn.ForceInvalidateColumns)
            {
                layoutChanged = true;
                flowGroupColumn.ForceInvalidateColumns = false;
            }
            else
            {
                layoutChanged = RowLayoutChanged(containerCount, templates, newDesiredColumnCount);
            }

            _desiredColumnCount = newDesiredColumnCount;

            if (!layoutChanged)             // REUSE VIEWS
            {
                if (_useGridAsMainRoot)
                {
                    for (int i = 0; i < containerCount; i++)
                    {
                        SetBindingContextForView(_rootLayoutAuto.Children[i], container[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < containerCount; i++)
                    {
                        SetBindingContextForView(_rootLayout.Children[i], container[i]);
                    }
                }
            }
            else             // RECREATE COLUMNS
            {
                _currentColumnTemplates = new List <DataTemplate>(templates);

                if (_useGridAsMainRoot)
                {
                    if (_rootLayoutAuto.Children.Count > 0)
                    {
                        _rootLayoutAuto.Children.Clear();
                    }

                    var colDefs = new ColumnDefinitionCollection();
                    for (int i = 0; i < _desiredColumnCount; i++)
                    {
                        colDefs.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(1d, GridUnitType.Star)
                        });
                    }
                    _rootLayoutAuto.ColumnDefinitions = colDefs;

                    for (int i = 0; i < containerCount; i++)
                    {
                        var view = templates[i].CreateContent() as View;
                        if (view == null)
                        {
                            throw new InvalidCastException("DataTemplate must return a View");
                        }

                        AddTapGestureToView(view);

                        SetBindingContextForView(view, container[i]);
                        if (containerCount == 0 || _desiredColumnCount == 0)
                        {
                            return;
                        }

                        AddViewToLayoutAutoHeightEnabled(view, containerCount, i);
                    }
                }
                else
                {
                    if (_rootLayout.Children.Count > 0)
                    {
                        _rootLayout.Children.Clear();
                    }

                    for (int i = 0; i < containerCount; i++)
                    {
                        var view = templates[i].CreateContent() as View;
                        if (view == null)
                        {
                            throw new InvalidCastException("DataTemplate must return a View");
                        }

                        AddTapGestureToView(view);

                        SetBindingContextForView(view, container[i]);
                        if (containerCount == 0 || _desiredColumnCount == 0)
                        {
                            return;
                        }

                        AddViewToLayoutAutoHeightDisabled(view, containerCount, i);
                    }
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Used to avoid linking issues
 /// eg. when using only XAML
 /// </summary>
 public static void Init()
 {
                 #pragma warning disable 0219
     var dummy = new FlowListView();
                 #pragma warning restore 0219
 }
        /// <summary>
        /// Override this method to execute an action when the BindingContext changes.
        /// </summary>
        /// <remarks></remarks>
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();

            var container = BindingContext as IList;

            if (container == null)
            {
                return;
            }

            FlowListView flowListView = null;

            if (_flowListViewRef.TryGetTarget(out flowListView) && flowListView != null)
            {
                _flowColumnTemplate = flowListView.FlowColumnTemplate;
                _desiredColumnCount = flowListView.DesiredColumnCount;
                _flowColumnExpand   = flowListView.FlowColumnExpand;
            }

            // Getting view types from templates
            var containerCount             = container.Count;
            IList <DataTemplate> templates = GetDataTemplates(container);
            bool layoutChanged             = RowLayoutChanged(containerCount, templates);

            if (!layoutChanged)             // REUSE VIEWS
            {
                if (_useGridAsMainRoot)
                {
                    for (int i = 0; i < containerCount; i++)
                    {
                        SetBindingContextForView(_rootLayoutAuto.Children[i], container[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < containerCount; i++)
                    {
                        SetBindingContextForView(_rootLayout.Children[i], container[i]);
                    }
                }
            }
            else             // RECREATE COLUMNS
            {
                if (_useGridAsMainRoot)
                {
                    if (_rootLayoutAuto.Children.Count > 0)
                    {
                        _rootLayoutAuto.Children.Clear();
                    }
                }
                else
                {
                    if (_rootLayout.Children.Count > 0)
                    {
                        _rootLayout.Children.Clear();
                    }
                }

                _currentColumnTemplates = new List <DataTemplate>(templates);

                for (int i = 0; i < containerCount; i++)
                {
                    var view = (View)templates[i].CreateContent();

                    view.GestureRecognizers.Add(new TapGestureRecognizer()
                    {
                        Command = new Command(async(obj) =>
                        {
                            await ExecuteTapGestureRecognizer(view);
                        })
                    });

                    SetBindingContextForView(view, container[i]);
                    AddViewToLayout(view, containerCount, i);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Override this method to execute an action when the BindingContext changes.
        /// </summary>
        /// <remarks></remarks>
        protected override void OnBindingContextChanged()
        {
            rootLayout.BindingContext = BindingContext;
            base.OnBindingContextChanged();

            var container = BindingContext as IList;

            if (container == null)
            {
                return;
            }

            // Getting view types from templates
            var          containerCount = container.Count;
            IList <Type> columnTypes    = GetViewTypesFromTemplates(container);
            bool         layoutChanged  = RowLayoutChanged(containerCount, columnTypes);

            if (!layoutChanged)             // REUSE VIEWS
            {
                for (int i = 0; i < containerCount; i++)
                {
                    SetBindingContextForView(rootLayout.Children[i], container[i]);
                }
            }
            else             // RECREATE COLUMNS
            {
                if (rootLayout.Children.Count > 0)
                {
                    rootLayout.Children.Clear();
                }

                for (int i = 0; i < containerCount; i++)
                {
                    var view = (View)Activator.CreateInstance(columnTypes[i]);
                    view.BindingContext = container[i];
                    view.GestureRecognizers.Add(new TapGestureRecognizer()
                    {
                        Command = new Command(async(obj) => {
                            var flowCell = view as IFlowViewCell;
                            if (flowCell != null)
                            {
                                flowCell.OnTapped();
                            }

                            FlowListView flowListView = null;
                            flowListViewRef.TryGetTarget(out flowListView);

                            if (flowListView != null)
                            {
                                int tapBackgroundEffectDelay = flowListView.FlowTappedBackgroundDelay;

                                try
                                {
                                    if (tapBackgroundEffectDelay != 0)
                                    {
                                        view.BackgroundColor = flowListView.FlowTappedBackgroundColor;
                                    }

                                    flowListView.FlowPerformTap(view.BindingContext);
                                }
                                finally
                                {
                                    if (tapBackgroundEffectDelay != 0)
                                    {
                                        await Task.Delay(tapBackgroundEffectDelay);
                                        view.BackgroundColor = Color.Transparent;
                                    }
                                }
                            }
                        })
                    });

                    SetBindingContextForView(view, container[i]);
                    AddViewToLayout(view, containerCount, i);
                }
            }
        }
		/// <summary>
		/// Used to avoid linking issues
		/// eg. when using only XAML
		/// </summary>
		public static void Init()
		{
			#pragma warning disable 0219
			var dummy = new FlowListView();
			#pragma warning restore 0219
		}