示例#1
0
        GridView Default(IEnumerable <object> items)
        {
            var control = new GridView
            {
                Size      = new Size(300, 100),
                DataStore = items
            };

            LogEvents(control);

            var dropDown = MyDropDown("DropDownKey");

            control.Columns.Add(new GridColumn {
                DataCell = new CheckBoxCell("Check"), Editable = true, AutoSize = true, Resizable = false
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Image", DataCell = new ImageViewCell("Image")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Text", DataCell = new TextBoxCell("Text"), Editable = true, Sortable = true
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Drop Down", DataCell = dropDown, Editable = true, Sortable = true
            });

            if (Platform.Supports <DrawableCell>())
            {
                var drawableCell = new DrawableCell();
                drawableCell.Paint += (sender, e) =>
                {
                    var m = e.Item as MyGridItem;
                    if (m != null)
                    {
                        if (e.CellState.HasFlag(DrawableCellStates.Selected))
                        {
                            e.Graphics.FillRectangle(Colors.Blue, e.ClipRectangle);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(Brushes.Cached(m.Color), e.ClipRectangle);
                        }
                        var rect = e.ClipRectangle;
                        rect.Inflate(-5, -5);
                        e.Graphics.DrawRectangle(Colors.White, rect);
                        e.Graphics.DrawLine(Colors.White, rect.Left, rect.Bottom, rect.MiddleX, rect.Top);
                        e.Graphics.DrawLine(Colors.White, rect.Right, rect.Bottom, rect.MiddleX, rect.Top);
                    }
                };
                control.Columns.Add(new GridColumn
                {
                    HeaderText = "Owner drawn",
                    DataCell   = drawableCell
                });
            }

            return(control);
        }
示例#2
0
        GridView Default(bool addItems = true)
        {
            var control = new GridView
            {
                Size = new Size(300, 100)
            };

            LogEvents(control);

            var dropDown = MyDropDown("DropDownKey");

            control.Columns.Add(new GridColumn {
                DataCell = new CheckBoxCell("Check"), Editable = true, AutoSize = true, Resizable = false
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Image", DataCell = new ImageViewCell("Image")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Text", DataCell = new TextBoxCell("Text"), Editable = true, Sortable = true
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Drop Down", DataCell = dropDown, Editable = true, Sortable = true
            });

#if Windows // Drawable cells - need to implement on other platforms.
            var drawableCell = new DrawableCell
            {
                PaintHandler = args => {
                    var m = args.Item as MyGridItem;
                    if (m != null)
                    {
                        args.Graphics.FillRectangle(Brushes.Cached(m.Color) as SolidBrush, args.CellBounds);
                    }
                }
            };
            control.Columns.Add(new GridColumn {
                HeaderText = "Owner drawn", DataCell = drawableCell
            });
#endif

            if (addItems)
            {
                var items = new DataStoreCollection();
                var rand  = new Random();
                for (int i = 0; i < 10000; i++)
                {
                    items.Add(new MyGridItem(rand, i, dropDown));
                }
                control.DataStore = items;
            }

            return(control);
        }
示例#3
0
        protected sealed override void OnPaint(PaintEventArgs e)
        {
            if (EnableDoubleBuffering)
            {
                var screen = ParentWindow.Screen;
                var scale  = screen.RealScale / screen.Scale;
                renderSize = Size.Round(e.ClipRectangle.Size * scale);
                if (bitmap == null ||
                    bitmap.Size.Width < renderSize.Width ||
                    bitmap.Size.Height < renderSize.Height)
                {
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }

                    bitmap = new Bitmap(renderSize, PixelFormat.Format32bppRgba);
                }
                var bitmapGraphics = new Graphics(bitmap);
                bitmapGraphics.Clear(Brushes.Cached(BackgroundColor));
                bitmapGraphics.ScaleTransform(scale);
                bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
                bitmapGraphics.SetClip(e.ClipRectangle * scale);                 // should be affected by transform

                var childArgs = new PaintEventArgs(bitmapGraphics, e.ClipRectangle);
                base.OnPaint(childArgs);

                OnBufferedPaint(childArgs);

                bitmapGraphics.Dispose();
                bitmapGraphics = null;
                e.Graphics.DrawImage(bitmap, new RectangleF(renderSize), e.ClipRectangle);
                if (Platform.IsWpf)
                {
                    // wpf runs out of resources fast here, so we garbage collect
                    GC.Collect();
                }
            }
            else
            {
                base.OnPaint(e);
                OnBufferedPaint(e);
            }
        }
示例#4
0
		Control DrawImageToRect()
		{
			var image64 = new Bitmap(new Size(64, 64), PixelFormat.Format32bppRgba);
			var image32 = new Bitmap(new Size(32, 32), PixelFormat.Format32bppRgba);

			using (var g = new Graphics(image64))
				g.Clear(Brushes.Cached(Colors.Green) as SolidBrush);

			using (var g = new Graphics(image32))
				g.Clear(Brushes.Cached(Colors.Blue) as SolidBrush);

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// draw the big image at the origin, but with a smaller dest rect
				g.DrawImage(image64, new RectangleF(0, 0, 32, 32), new RectangleF(0, 0, 32, 32));
				// draw two guide images to indicate how big the green image should be
				g.DrawImage(image32, new PointF(70, 0));
				g.DrawImage(image32, new PointF(0, 70));
			}
			return new DrawableImageView { Image = bitmap };
		}
示例#5
0
        public Graphics BeginDraw(PaintEventArgs e)
        {
            if (UseOffScreenBitmap)
            {
                if (OffscreenBitmap == null ||
                    OffscreenBitmap.Size.Width < e.ClipRectangle.Width ||
                    OffscreenBitmap.Size.Height < e.ClipRectangle.Height)
                {
                    if (OffscreenBitmap != null)
                    {
                        OffscreenBitmap.Dispose();
                    }

                    OffscreenBitmap = new Bitmap(Size.Round(e.ClipRectangle.Size), PixelFormat.Format32bppRgba);
                }
                bitmapGraphics = new Graphics(OffscreenBitmap);
                bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
                bitmapGraphics.SetClip(e.ClipRectangle);
                bitmapGraphics.Clear(Brushes.Cached(drawable.BackgroundColor));
                return(bitmapGraphics);
            }
            return(e.Graphics);
        }
示例#6
0
        GridView CreateGrid()
        {
            var control = new GridView
            {
                Size = new Size(300, 100)
            };

            LogEvents(control);

            var dropDown = MyDropDown("DropDownKey");

            control.Columns.Add(new GridColumn {
                DataCell = new CheckBoxCell("Check"), AutoSize = true, Resizable = false
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Image", DataCell = new ImageViewCell("Image"), Resizable = false
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "ImageText", DataCell = new ImageTextCell("Image", "Text")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Text", DataCell = new TextBoxCell("Text"), Sortable = true
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Progress", DataCell = new ProgressCell("Progress")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Drop Down", DataCell = dropDown, Sortable = true
            });
            if (Platform.Supports <CustomCell>())
            {
                //control.ReloadSelectedCells = true;
                //control.SelectedRowsChanged += (sender, e) => control.ReloadData(control.SelectedRows);
                var col = new GridColumn {
                    HeaderText = "Custom", Sortable = true, DataCell = new MyCustomCell()
                };
                control.Columns.Add(col);
            }

            if (Platform.Supports <DrawableCell>())
            {
                var drawableCell = new DrawableCell();
                drawableCell.Paint += (sender, e) =>
                {
                    var m = e.Item as MyGridItem;
                    if (m != null)
                    {
                        if (e.CellState.HasFlag(CellStates.Selected))
                        {
                            e.Graphics.FillRectangle(Colors.Blue, e.ClipRectangle);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(Brushes.Cached(m.Color), e.ClipRectangle);
                        }
                        var rect = e.ClipRectangle;
                        rect.Inflate(-5, -5);

                        var color = e.CellState.HasFlag(CellStates.Editing) ? Colors.Black : Colors.White;
                        e.Graphics.DrawRectangle(color, rect);
                        e.Graphics.DrawLine(color, rect.Left, rect.Bottom, rect.MiddleX, rect.Top);
                        e.Graphics.DrawLine(color, rect.Right, rect.Bottom, rect.MiddleX, rect.Top);
                    }
                };
                control.Columns.Add(new GridColumn
                {
                    HeaderText = "Owner drawn",
                    DataCell   = drawableCell
                });
            }

            return(control);
        }
示例#7
0
        SearchBox CreateSearchBox(SelectableFilterCollection <MyGridItem> filtered)
        {
            var filterText = new SearchBox {
                PlaceholderText = "Filter"
            };

            filterText.TextChanged += (s, e) =>
            {
                var filterItems = (filterText.Text ?? "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (filterItems.Length == 0)
                {
                    filtered.Filter = null;
                }
                else
                {
                    filtered.Filter = i =>
                    {
                        // Every item in the split filter string should be within the Text property
                        foreach (var filterItem in filterItems)
                        {
                            if (i.Text.IndexOf(filterItem, StringComparison.OrdinalIgnoreCase) == -1)
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                };
            };
            return(filterText);
        }

        GridView CreateGrid()
        {
            var control = new GridView
            {
                Size = new Size(300, 100)
            };

            LogEvents(control);

            var dropDown = MyDropDown("DropDownKey");

            control.Columns.Add(new GridColumn {
                DataCell = new CheckBoxCell("Check"), AutoSize = true, Resizable = false
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Image", DataCell = new ImageViewCell("Image")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "ImageText", DataCell = new ImageTextCell("Image", "Text")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Text", DataCell = new TextBoxCell("Text"), Sortable = true
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Progress", DataCell = new ProgressCell("Progress")
            });
            control.Columns.Add(new GridColumn {
                HeaderText = "Drop Down", DataCell = dropDown, Sortable = true
            });

            if (Platform.Supports <DrawableCell>())
            {
                var drawableCell = new DrawableCell();
                drawableCell.Paint += (sender, e) =>
                {
                    var m = e.Item as MyGridItem;
                    if (m != null)
                    {
                        if (e.CellState.HasFlag(DrawableCellStates.Selected))
                        {
                            e.Graphics.FillRectangle(Colors.Blue, e.ClipRectangle);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(Brushes.Cached(m.Color), e.ClipRectangle);
                        }
                        var rect = e.ClipRectangle;
                        rect.Inflate(-5, -5);
                        e.Graphics.DrawRectangle(Colors.White, rect);
                        e.Graphics.DrawLine(Colors.White, rect.Left, rect.Bottom, rect.MiddleX, rect.Top);
                        e.Graphics.DrawLine(Colors.White, rect.Right, rect.Bottom, rect.MiddleX, rect.Top);
                    }
                };
                control.Columns.Add(new GridColumn
                {
                    HeaderText = "Owner drawn",
                    DataCell   = drawableCell
                });
            }

            return(control);
        }

        IEnumerable <MyGridItem> CreateItems()
        {
            var rand = new Random();

            for (int i = 0; i < 10000; i++)
            {
                yield return(new MyGridItem(rand, i));
            }
        }

        ContextMenu CreateContextMenu(GridView grid, SelectableFilterCollection <MyGridItem> filtered)
        {
            // Context menu
            var menu = new ContextMenu();
            var item = new ButtonMenuItem {
                Text = "Click Me!"
            };

            item.Click += (sender, e) =>
            {
                if (grid.SelectedRows.Any())
                {
                    Log.Write(item, "Click, Rows: {0}", SelectedRowsString(grid));
                }
                else
                {
                    Log.Write(item, "Click, no item selected");
                }
            };
            menu.Items.Add(item);

            // Delete menu item: deletes the item from the store, the UI updates via the binding.
            var deleteItem = new ButtonMenuItem {
                Text = "Delete Item"
            };

            deleteItem.Click += (s, e) =>
            {
                var i = grid.SelectedItems.First() as MyGridItem;
                if (i != null)
                {
                    filtered.Remove(i);
                }
            };
            menu.Items.Add(deleteItem);

            // Insert item: inserts an item into the store, the UI updates via the binding.
            var insertItem = new ButtonMenuItem {
                Text = "Insert Item at the start of the list"
            };

            insertItem.Click += (s, e) =>
            {
                var i = grid.SelectedItems.First() as MyGridItem;
                if (i != null)
                {
                    filtered.Insert(0, new MyGridItem(new Random(), 0));
                }
            };
            menu.Items.Add(insertItem);

            var subMenu = menu.Items.GetSubmenu("Sub Menu");

            item = new ButtonMenuItem {
                Text = "Item 5"
            };
            item.Click += (s, e) => Log.Write(item, "Clicked");
            subMenu.Items.Add(item);
            item = new ButtonMenuItem {
                Text = "Item 6"
            };
            item.Click += (s, e) => Log.Write(item, "Clicked");
            subMenu.Items.Add(item);

            return(menu);
        }
示例#8
0
 private sd.Brush GetBrush(Color color)
 {
     return((sd.Brush)Brushes.Cached(color, this.Generator).ControlObject);
 }