static void OnRatingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RatingCell cell = (RatingCell)d;

            for (int i = 0; i < cell.Children.Count; i++)
            {
                cell.Children[i].Opacity = i < cell.Rating ? ON : OFF;
            }
        }
        void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // calculate rating based on the index of the star
            Image      img   = sender as Image;
            RatingCell cell  = img.Parent as RatingCell;
            int        index = cell.Children.IndexOf(img);

            if (index > 0 || e.GetPosition(img).X > img.Width / 3)
            {
                index++;
            }

            // apply the new rating
            cell.Rating = index;
            Animate(img);
        }
        // bind a cell to a range
        public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange range)
        {
            // get row/col
            var row = grid.Rows[range.Row];
            var col = grid.Columns[range.Column];
            var gr  = row as GroupRow;

            // no border for group rows
            if (gr != null)
            {
                bdr.BorderThickness = _emptyThickness;
            }

            // bind the tree cells
            if (gr != null && range.Column == 0)
            {
                BindGroupRowCell(grid, bdr, range);
                return;
            }

            // bind cells in regular data rows
            var colName = col.ColumnName;

            if (colName == "Name")
            {
                bdr.Child = new SongCell(row);
                return;
            }
            if (colName == "Rating")
            {
                var song = row.DataItem as Song;
                if (song != null)
                {
                    // create rating control to represent this cell
                    // notes:
                    // - the data context is provided by the Border element, and
                    // - the binding is provided by the column
                    var cell = new RatingCell();
                    cell.SetBinding(RatingCell.RatingProperty, col.Binding);
                    bdr.Child = cell;
                    return;
                }
            }

            // default binding
            base.CreateCellContent(grid, bdr, range);
        }
Ejemplo n.º 4
0
        // bind a cell to a range
        public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange range)
        {
            // get row/col
            var row = grid.Rows[range.Row];
            var col = grid.Columns[range.Column];
            var gr = row as GroupRow;

            // no border for group rows
            if (gr != null)
            {
                bdr.BorderThickness = _emptyThickness;
            }

            // bind the tree cells
            if (gr != null && range.Column == 0)
            {
                BindGroupRowCell(grid, bdr, range);
                return;
            }

            // bind cells in regular data rows
            var colName = col.ColumnName;
            if (colName == "Name")
            {
                bdr.Child = new SongCell(row);
                return;
            }
            if (colName == "Rating")
            {
                var song = row.DataItem as Song;
                if (song != null)
                {
                    // create rating control to represent this cell
                    // notes:
                    // - the data context is provided by the Border element, and
                    // - the binding is provided by the column
                    var cell = new RatingCell();
                    cell.SetBinding(RatingCell.RatingProperty, col.Binding);
                    bdr.Child = cell;
                    return;
                }
            }

            // default binding
            base.CreateCellContent(grid, bdr, range);
        }