示例#1
0
        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;
            }
        }
示例#2
0
        void img_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            // calculate rating based on the index of the star
            var        star  = sender as ContentControl;
            RatingCell cell  = star.Parent as RatingCell;
            int        index = cell.Children.IndexOf(star);

            if (index > 0 || e.GetCurrentPoint(star).Position.X > star.Width / 3)
            {
                index++;
            }

            // apply the new rating
            cell.Rating = index;
            Animate(star);
        }
        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);
        }
示例#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);
        }
        // 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 first cell in each group row to collapse/expand
            if (gr != null && range.Column == 0)
            {
                BindGroupRowCell(grid, bdr, range);
                return;
            }

            // bind regular data cells
            switch (col.ColumnName)
            {
            // show names with images
            case "Name":
                bdr.Child = new SongCell(row);
                return;

            // show ratings with stars
            case "Rating":
                var song = row.DataItem as Song;
                if (song != null && gr == null)
                {
                    var cell = new RatingCell();
                    cell.SetBinding(RatingCell.RatingProperty, col.Binding);
                    bdr.Child = cell;
                }
                return;
            }

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