Example #1
0
        protected override void OnBindingContextChanged()
        {
            // Triggers event
            if (BindingContext is INotifyPropertyChanged model)
            {
                model.PropertyChanged += (obj, e) => RowTrigger.SetTriggerStyle(this, e.PropertyName);
            }

            // Set binding context for custom cells
            foreach (var item in cells)
            {
                if (item.IsCustomTemplate && item.Wrapper?.Content != null)
                {
                    item.Wrapper.Content.BindingContext = BindingContext;
                }
            }

            // Started find FIRST active trigger
            if (this.DataGrid.RowTriggers.Count > 0)
            {
                foreach (var trigg in this.DataGrid.RowTriggers)
                {
                    if (trigg.CheckTriggerActivated(BindingContext))
                    {
                        this.enableTrigger = trigg;
                        break;
                    }
                    //var trigger = RowTrigger.SetTriggerStyle(this, trigg.PropertyTrigger, false);
                    //if (trigger != null)
                    //{
                    //    this.enableTrigger = trigger;
                    //    break;
                    //}
                }
            }

            // Set text value for standart cell
            foreach (var item in cells)
            {
                if (item.IsCustomTemplate || item.AutoNumber != Enums.AutoNumberType.None)
                {
                    continue;
                }

                if (item.Column.PropertyName != null)
                {
                    item.Label.SetBinding(Label.TextProperty, new Binding(item.Column.PropertyName, BindingMode.Default,
                                                                          stringFormat: item.Column.StringFormat, source: BindingContext));
                }
            }

            // Render first style
            UpdateStyle();
        }
Example #2
0
        public GridRow(object context, StackList host, int id, bool showBottomLine, bool isAutoNumber)
        {
            Context        = context;
            BindingContext = context;
            DataGrid       = host.DataGrid;
            Index          = id;
            isLineVisible  = showBottomLine;

            IsClippedToBounds = true;
            VerticalOptions   = LayoutOptions.Start;
            HorizontalOptions = LayoutOptions.FillAndExpand;
            Cells             = new GridCell[DataGrid.Columns.Count];

            // Triggers event
            if (context is INotifyPropertyChanged model && DataGrid.RowTriggers.Count > 0)
            {
                model.PropertyChanged += (obj, e) => RowTrigger.SetTriggerStyle(this, e.PropertyName);
            }

            // Selection box
            SelectionBox = new BoxView();
            SelectionBox.InputTransparent = true;
            SelectionBox.BackgroundColor  = Color.Transparent;
            Children.Add(SelectionBox);

            // Init cells
            for (int i = 0; i < DataGrid.Columns.Count; i++)
            {
                var column = DataGrid.Columns[i];
                var cell   = new GridCell(this, column);

                Children.Add(cell.Wrapper);
                Children.Add(cell.Content);
                Cells[i] = cell;
            }

            // Add tap system event
            if (DataGrid.TapColor != Color.Default ||
                DataGrid.CommandLongTapItem != null ||
                DataGrid.CommandSelectedItem != null)
            {
                Touch.SetHost(this, DataGrid);
            }

            //Touch.SetSelect(this, new Command(ActionRowSelect));

            //if (DataGrid.TapColor != Color.Default)
            //    Touch.SetColor(this, DataGrid.TapColor);

            //if (DataGrid.CommandSelectedItem != null)
            //    Touch.SetTap(this, DataGrid.CommandSelectedItem);

            //if (DataGrid.CommandLongTapItem != null)
            //    Touch.SetLongTap(this, DataGrid.CommandLongTapItem);


            // Create horizontal line table
            Line = new BoxView();
            Line.BackgroundColor  = DataGrid.BorderColor;
            Line.HeightRequest    = DataGrid.BorderWidth;
            Line.InputTransparent = true;
            Children.Add(Line);

            // Auto number
            if (DataGrid.IsAutoNumberCalc && isAutoNumber)
            {
                UpdateAutoNumeric(Index);
            }

            // find FIRST active trigger
            if (this.DataGrid.RowTriggers.Count > 0)
            {
                foreach (var trigg in this.DataGrid.RowTriggers)
                {
                    if (trigg.CheckTriggerActivated(BindingContext))
                    {
                        this.EnabledTrigger = trigg;
                        break;
                    }
                }
            }

            // Render style
            UpdateStyle();
        }