private DemoGridAlign() { var grid = new Grid(); grid.Name = "LayoutRoot"; grid.Margin = new Thickness(20, 10); grid.Width = 400; grid.Height = 220; grid.HorizontalAlignment = MicroWPF.HorizontalAlignment.Center; grid.VerticalAlignment = MicroWPF.VerticalAlignment.Center; grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); for (int r = 0; r < 4; r++) { for (int c = 0; c < 4; c++) { var sp = new StackPanel(); sp.Name = "S" + r + c; sp.Background = ((c + r) & 1) == 0 ? Colors.Gray : Colors.DimGray; grid.SetRowCol(sp, r, c); grid.Children.Add(sp); var btn = new PushButton(); btn.Name = "B" + r + c; btn.Text = btn.Name; btn.HorizontalAlignment = (HorizontalAlignment)c; btn.VerticalAlignment = (VerticalAlignment)r; grid.SetRowCol(btn, r, c); grid.Children.Add(btn); if (r == 3) { if (c == 0) { btn.Text = "Prev"; btn.Click += new EventHandler(btn_prev_Click); } else if (c == 3) { btn.Text = "Next"; btn.Click += new EventHandler(btn_next_Click); } } } } this.Content = grid; }
private DemoFont() { var grid = new Grid(); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1.5f, GridUnitType.Star); int c = 0; StackPanel stack = null; for (int i = 16; i < 32; i++) { if (i == 25) { stack = null; } if (stack == null) { stack = new StackPanel(); grid.Children.Add(stack); grid.SetRowCol(stack, 0, c++); } var tb = new TextBlock() { Font = i, Text = i + ": Betty the cat!", HorizontalAlignment = MicroWPF.HorizontalAlignment.Left, VerticalAlignment = MicroWPF.VerticalAlignment.Center, Margin = new Thickness(5) }; if ((i & 1) != 0) { tb.Background = Colors.DarkBlue; tb.Foreground = Colors.Yellow; } else { tb.Background = Colors.DarkOrange; tb.Foreground = Colors.Lime; } stack.Children.Add(tb); } var btn_next = new PushButton() { Text = "Next" }; btn_next.Click += new EventHandler(btn_next_Click); btn_next.HorizontalAlignment = MicroWPF.HorizontalAlignment.Right; btn_next.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; grid.Children.Add(btn_next); this.Content = grid; }
private FontDemo() { //create a grid-layout container var container = new Grid(); container.AddColumnDefinition(1, GridUnitType.Star); container.AddColumnDefinition(1.5f, GridUnitType.Star); //the total native fonts are 16, so arrange a short sample //each in two columns. In every column the strings will //be stacked vertically int c = 0; StackPanel stack = null; for (int i = 16; i < 32; i++) { //create a stack-panel if (i == 25) { stack = null; } if (stack == null) { stack = new StackPanel(); container.Children.Add(stack); container.SetRowCol(stack, 0, c++); } //create a text block styled with the current font var tb = new TextBlock() { Font = i, Text = i + ": I love WPF!", HorizontalAlignment = MicroWPF.HorizontalAlignment.Left, VerticalAlignment = MicroWPF.VerticalAlignment.Center, Margin = new Thickness(5) }; //alternate the text foreground color if ((i & 1) != 0) { tb.Background = Colors.DarkBlue; tb.Foreground = Colors.Yellow; } else { tb.Background = Colors.DarkOrange; tb.Foreground = Colors.Lime; } //add the text block to the stack-panel stack.Children.Add(tb); } //set the group as content of the page this.Content = container; }
private GridRowColDemo() { //create a grid container var grid = new Grid(); grid.Width = 400; grid.Height = 200; grid.Margin = new Thickness(0, 20, 0, 10); //slice the total width into some columns grid.AddColumnDefinition(100); //default unit is pixels grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(3, GridUnitType.Star); //slice the total height into some rows grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(50, GridUnitType.Pixel); grid.AddRowDefinition(1, GridUnitType.Star); //create a series of boxes, shaded differently, //then add each box to the respective cell for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { //create a box, shaded as the sequence progression var box = this.CreateBox(_colors[c + r * 3]); //define the location (row and column) where the box //should be located grid.SetRowCol(box, r, c); //add the box as child of the grid grid.Children.Add(box); } } //create a container whose children will be stacked vertically var vertical = new StackPanel(); vertical.HorizontalAlignment = MicroWPF.HorizontalAlignment.Center; vertical.VerticalAlignment = MicroWPF.VerticalAlignment.Center; vertical.Children.Add( grid ); vertical.Children.Add( new TextBlock() { Text = "The Grid is sliced along rows and columns." } ); //set the group as content of the page this.Content = vertical; }
private NavigationDemo2() { //create a grid-layout container var container = new Grid(); container.AddColumnDefinition(1, GridUnitType.Star); container.AddColumnDefinition(1, GridUnitType.Star); container.AddRowDefinition(1, GridUnitType.Star); container.AddRowDefinition(80); //create a text label var tb = new TextBlock(); tb.Text = "This is page #2."; tb.Foreground = Colors.Aquamarine; tb.Font = 28; tb.Margin = new Thickness(20); tb.VerticalAlignment = MicroWPF.VerticalAlignment.Top; //add the label as child of the container container.Children.Add(tb); container.SetRowCol(tb, 0, 0, 1, 2); { //create a pushbutton var but_prev = new PushButton(); but_prev.Text = "Prev"; but_prev.Margin = new Thickness(20, 10); but_prev.HorizontalAlignment = MicroWPF.HorizontalAlignment.Left; but_prev.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; but_prev.Click += new EventHandler(btn_prev_Click); //add the button as child of the container container.Children.Add(but_prev); container.SetRowCol(but_prev, 1, 0); } { //create a pushbutton var btn_next = new PushButton(); btn_next.Text = "Next"; btn_next.Margin = new Thickness(20, 10); btn_next.HorizontalAlignment = MicroWPF.HorizontalAlignment.Right; btn_next.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; btn_next.Click += new EventHandler(btn_next_Click); //add the button as child of the container container.Children.Add(btn_next); container.SetRowCol(btn_next, 1, 1); } //set the group as content of the page this.Content = container; }
private DemoKnobs() { var btn_prev = new PushButton() { Margin = new Thickness(10, 5), Text = "Prev" }; btn_prev.Click += new EventHandler(btn_prev_Click); //var btn_next = new WidgetButton() { Margin = new Thickness(10, 5), Text = "Next" }; //btn_next.Click += new EventHandler(btn_next_Click); //btn_next.HAlign = HorizontalAlignment.Right; var grid = new Grid(); grid.Name = "GRID"; grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddRowDefinition(3, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); { var dial = new DialKnob(); dial.Max = 100; dial.Width = 135; dial.HorizontalAlignment = HorizontalAlignment.Center; dial.VerticalAlignment = VerticalAlignment.Center; grid.SetRowCol(dial, 0, 0); grid.Children.Add(dial); } { var dial = new DialKnob(); dial.Max = 100; dial.Width = 135; dial.HorizontalAlignment = HorizontalAlignment.Center; dial.VerticalAlignment = VerticalAlignment.Center; grid.SetRowCol(dial, 0, 1); grid.Children.Add(dial); } { var dial = new DialKnob(); dial.Max = 100; dial.Width = 135; dial.HorizontalAlignment = HorizontalAlignment.Center; dial.VerticalAlignment = VerticalAlignment.Center; grid.SetRowCol(dial, 0, 2); grid.Children.Add(dial); } { grid.SetRowCol(btn_prev, 1, 0); grid.Children.Add(btn_prev); } //{ // grid.SetRowCol(btn_next, 2, 1); // grid.Children.Add(btn_next); //} this.Content = grid; }
private DemoSliders() { var btn_prev = new PushButton() { Margin = new Thickness(10, 5), Text = "Prev" }; btn_prev.Click += new EventHandler(btn_prev_Click); btn_prev.HorizontalAlignment = MicroWPF.HorizontalAlignment.Left; btn_prev.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; var btn_next = new PushButton() { Margin = new Thickness(10, 5), Text = "Next" }; btn_next.Click += new EventHandler(btn_next_Click); btn_next.HorizontalAlignment = HorizontalAlignment.Right; btn_next.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; var grid = new Grid(); grid.Name = "GRID"; grid.Margin = new Thickness(20); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(2, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); { var vslider = new Slider(); vslider.Max = 100; vslider.Width = 20; vslider.Height = 200; grid.SetRowCol(vslider, 0, 0, 3, 1); grid.Children.Add(vslider); } { var vslider = new Slider(); vslider.Max = 100; vslider.Width = 20; vslider.Height = 200; grid.SetRowCol(vslider, 0, 1, 3, 1); grid.Children.Add(vslider); } { var hslider = new Slider(); hslider.Max = 100; hslider.Width = 200; hslider.Height = 20; grid.SetRowCol(hslider, 0, 2); grid.Children.Add(hslider); } { var hslider = new Slider(); hslider.Max = 100; hslider.Width = 200; hslider.Height = 20; grid.SetRowCol(hslider, 1, 2); grid.Children.Add(hslider); } { grid.SetRowCol(btn_prev, 2, 2); grid.Children.Add(btn_prev); } { grid.SetRowCol(btn_next, 2, 2); grid.Children.Add(btn_next); } this.Content = grid; }
private DemoGridSpan() { var grid = new Grid(); grid.Margin = new Thickness(20, 10); grid.Width = 400; grid.Height = 220; grid.HorizontalAlignment = MicroWPF.HorizontalAlignment.Center; grid.VerticalAlignment = MicroWPF.VerticalAlignment.Center; grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddColumnDefinition(2, GridUnitType.Star); grid.AddColumnDefinition(3, GridUnitType.Star); grid.AddColumnDefinition(1, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); grid.AddRowDefinition(2, GridUnitType.Star); grid.AddRowDefinition(3, GridUnitType.Star); grid.AddRowDefinition(1, GridUnitType.Star); var btn_prev = new PushButton() { Text = "Prev" }; btn_prev.Click += new EventHandler(btn_prev_Click); btn_prev.HorizontalAlignment = HorizontalAlignment.Left; grid.SetRowCol(btn_prev, 0, 0, 1, 2); var btn_next = new PushButton() { Text = "Next" }; btn_next.Click += new EventHandler(btn_next_Click); grid.SetRowCol(btn_next, 0, 2, 1, 2); grid.Children.Add(btn_next); var btn_dlg = new PushButton() { Margin = new Thickness(10, 5), HorizontalAlignment = HorizontalAlignment.Stretch }; btn_dlg.Text = "Dialog"; btn_dlg.Click += new EventHandler(btn_dlg_Click); grid.SetRowCol(btn_dlg, 1, 0, 3, 2); grid.Children.Add(btn_dlg); var vstack2 = new StackPanel() { Name = "V2", Background = Colors.Red }; vstack2.Children.Add(new TextBlock() { Font = 21, Text = "Betty the cat!", HorizontalAlignment = MicroWPF.HorizontalAlignment.Left, Background = Colors.DarkOrange, Foreground = Colors.Lime, Margin = new Thickness(20, 20), }); grid.Children.Add(vstack2); grid.SetRowCol(vstack2, 1, 2, 1, 2); { var toggle = new ToggleSwitch() { VerticalAlignment = MicroWPF.VerticalAlignment.Center, Font = 31 }; grid.SetRowCol(toggle, 2, 2); grid.Children.Add(toggle); } { var toggle = new ToggleSwitch() { VerticalAlignment = MicroWPF.VerticalAlignment.Center, Font = 20 }; grid.SetRowCol(toggle, 3, 2); grid.Children.Add(toggle); } this.Content = grid; }
void button_Click(object sender, EventArgs e) { //create a secondary window which will host the container var dialog = new Window(); dialog.Background = Colors.Gray; dialog.BorderColor = Colors.Gainsboro; dialog.BorderThickness = new Thickness(2); dialog.Width = 300; dialog.Height = 200; //create a grid-layout container var container = new Grid(); container.AddColumnDefinition(1, GridUnitType.Star); container.AddColumnDefinition(1, GridUnitType.Star); container.AddRowDefinition(1, GridUnitType.Star); container.AddRowDefinition(80); //set the container as content of the window dialog.Content = container; //create a text label var tb = new TextBlock(); tb.Text = "this is a dialog window."; tb.Foreground = Colors.Yellow; tb.Font = 28; tb.Margin = new Thickness(20); tb.VerticalAlignment = MicroWPF.VerticalAlignment.Top; //add the label as child of the container container.Children.Add(tb); container.SetRowCol(tb, 0, 0, 1, 2); { //create a pushbutton var button = new PushButton(); button.Text = "Close"; button.Margin = new Thickness(20, 10); button.HorizontalAlignment = MicroWPF.HorizontalAlignment.Left; button.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; button.Click += (s_, e_) => dialog.Close(); //add the button as child of the container //(also sibling of the label) container.Children.Add(button); container.SetRowCol(button, 1, 0); } { //create a pushbutton var button = new PushButton(); button.Text = "Options"; button.Margin = new Thickness(20, 10); button.HorizontalAlignment = MicroWPF.HorizontalAlignment.Right; button.VerticalAlignment = MicroWPF.VerticalAlignment.Bottom; button.Click += new EventHandler(button2_Click); //add the button as child of the container //(also sibling of the label) container.Children.Add(button); container.SetRowCol(button, 1, 1); } //finally, show the dialog dialog.ShowDialog(); }
public void RandomGrid() { Random random = new Random(); Grid subGrid1 = new Grid(); subGrid1.AddColumnDefinition(Definition.Auto); subGrid1.AddColumnDefinition(Definition.Auto); subGrid1.AddRowDefinition(Definition.Auto); subGrid1.AddRowDefinition(Definition.Auto); Point subGrid1Location = randomLocation(); for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { subGrid1.AddChild(randomElement(x, y, true), x, y); } } Grid subGrid2 = new Grid(); subGrid2.AddColumnDefinition(Definition.Auto); subGrid2.AddColumnDefinition(Definition.Auto); subGrid2.AddRowDefinition(Definition.Auto); subGrid2.AddRowDefinition(Definition.Auto); Point subGrid2Location = randomLocation(); for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { subGrid2.AddChild(randomElement(x, y, true), x, y); } } while (subGrid1Location == subGrid2Location) { subGrid2Location = randomLocation(); } Grid mainGrid = new Grid(new Margin(100, 0, 100, 0)); mainGrid.PersistantHighlight = true; mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Fill); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Fill); for (int x = 0; x < 5; x++) { for (int y = 0; y < 4; y++) { if (new Point(x, y) == subGrid1Location) { mainGrid.AddChild(subGrid1, x, y); } else if (new Point(x, y) == subGrid2Location) { mainGrid.AddChild(subGrid2, x, y); } else { mainGrid.AddChild(randomElement(x, y, false), x, y); } } } Item = mainGrid; Point randomLocation() { return(new Point(random.Next(0, 5), random.Next(0, 4))); } UIElement randomElement(int x, int y, bool small) { int decider = random.Next(0, 3); switch (decider) { case 0: return(new Menu1Button(small?buttonTexture2:buttonTexture1, OnButtonPress, new ButtonArgs((x + ", " + y).ToString()))); case 1: return(new Menu1TextButton(bitmapFont, "Button", OnButtonPress, new ButtonArgs((x + ", " + y).ToString()))); default: return(new Image(small?imageTexture2:imageTexture1)); } } }
public Menu1(Texture2D texture, Texture2D buttonTexture1, Texture2D buttonTexture2, Texture2D imageTexture1, Texture2D imageTexture2, BitmapFont bitmapFont) { this.Background = texture; this.Width = texture.Width; this.Height = texture.Height; Origin = new Vector2(Width * .5f, Height * .5f); this.buttonTexture1 = buttonTexture1; this.buttonTexture2 = buttonTexture2; this.imageTexture1 = imageTexture1; this.imageTexture2 = imageTexture2; this.bitmapFont = bitmapFont; Grid subGrid = new Grid(); subGrid.AddColumnDefinition(Definition.Auto); subGrid.AddColumnDefinition(Definition.Auto); subGrid.AddRowDefinition(Definition.Auto); subGrid.AddRowDefinition(Definition.Auto); subGrid.AddChild(new Menu1Button(buttonTexture2, OnButtonPress, new ButtonArgs("0, 0")), 0, 0); subGrid.AddChild(new Menu1Button(buttonTexture2, OnButtonPress, new ButtonArgs("1, 0")), 1, 0); subGrid.AddChild(new Menu1Button(buttonTexture2, OnButtonPress, new ButtonArgs("0, 1")), 0, 1); subGrid.AddChild(new Menu1Button(buttonTexture2, OnButtonPress, new ButtonArgs("1, 1")), 1, 1); Grid mainGrid = new Grid(new Margin(100, 0, 100, 0)); mainGrid.PersistantHighlight = true; mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Auto); mainGrid.AddColumnDefinition(Definition.Fill); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Auto); mainGrid.AddRowDefinition(Definition.Fill); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("0, 0")), 0, 0); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("1, 0")), 1, 0); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("2, 0")), 2, 0); mainGrid.AddChild(new Image(imageTexture1), 3, 0); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("4, 0")), 4, 0); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("0, 1")), 0, 1); mainGrid.AddChild(subGrid, 1, 1); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("2, 1")), 2, 1); mainGrid.AddChild(new Menu1TextButton(bitmapFont, "Button", OnButtonPress, new ButtonArgs("3, 1")), 3, 1); mainGrid.AddChild(new Image(imageTexture1), 4, 1); mainGrid.AddChild(new Image(imageTexture1), 0, 2); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("1, 2")), 1, 2); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("2, 2")), 2, 2); mainGrid.AddChild(new Image(imageTexture1), 3, 2); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("4, 2")), 4, 2); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("0, 3")), 0, 3); mainGrid.AddChild(new Menu1TextButton(bitmapFont, "Button", OnButtonPress, new ButtonArgs("1, 3")), 1, 3); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("2, 3")), 2, 3); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("3, 3")), 3, 3); mainGrid.AddChild(new Menu1Button(buttonTexture1, OnButtonPress, new ButtonArgs("4, 3")), 4, 3); Item = mainGrid; }
private GridSpanningDemo() { //create a grid container var grid = new Grid(); grid.Width = 400; grid.Height = 200; grid.Margin = new Thickness(0, 20, 0, 10); //slice the total width into 9 equally-sized columns for (int i = 0; i < 9; i++) { grid.AddColumnDefinition(1, GridUnitType.Star); } //slice the total height into 5 equally-sized rows for (int i = 0; i < 5; i++) { grid.AddRowDefinition(1, GridUnitType.Star); } //create a series of boxes, shaded differently, //then make every box spanning some cells for (int r = 0; r < 5; r++) { //create a box, shaded as the sequence progression var box = this.CreateBox(_colors[r]); //define the location (row and column) and the spanning grid.SetRowCol(box, r, 4 - r, 1, 1 + r * 2); //add the box as child of the grid grid.Children.Add(box); } for (int c = 0; c < 4; c++) { { //create a box, shaded as the sequence progression var box = this.CreateBox(_colors[c]); //define the location (row and column) and the spanning grid.SetRowCol(box, 0, c, 4 - c, 1); //add the box as child of the grid grid.Children.Add(box); } { //create a box, shaded as the sequence progression var box = this.CreateBox(_colors[c]); //define the location (row and column) and the spanning grid.SetRowCol(box, 0, c + 5, c + 1, 1); //add the box as child of the grid grid.Children.Add(box); } } //create a container whose children will be stacked vertically var vertical = new StackPanel(); vertical.HorizontalAlignment = MicroWPF.HorizontalAlignment.Center; vertical.VerticalAlignment = MicroWPF.VerticalAlignment.Center; vertical.Children.Add( grid ); vertical.Children.Add( new TextBlock() { Text = "Grid cells' row- and column-spanning." } ); //set the group as content of the page this.Content = vertical; }