Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controls - colors, dynamics
#1
Short script to demonstrate dynamic element content change, colors, WPF controls.
   
Code:
Copy      Help
//.
using System.Windows.Controls;
using System.Windows.Media;

var b = new wpfBuilder("Colorful Window").WinSize(400).Brush(Brushes.LightCoral);

//examples of some controls
b.StartGrid();
b.R.StartStack().Add<Label>(out Label label1, "Label").Font("Trebuchet", size: 18, italic: true).Add<Label>(out Label label2, "Label (2nd in stack) with small font").Font("Courier", size: 10).End();
// Note the reversed order of 'out' and label text above. This allows the label1.Content assignment to replace the text 'Label' instead of following it. Try reversing the order!
// You'll see that reversing the order causes label1.Content to be placed after 'Label' instead of replacing it.
b.R.Add("Date Picker", out System.Windows.Controls.DatePicker cal);
b.End();
b.R.Add("Textblock", out TextBlock tb1).Text("Oversize text").Font("Comic Sans MS", size: 24, bold: true, italic: true).Brush(null, Brushes.Beige);
b.R.Add("Text", out TextBox text1).Brush(Brushes.DarkRed, Brushes.Beige).Focus(); //Label and TextBox
b.R.Add("Combo", out ComboBox combo1).Items("Zero|One|Two|Dialog"); //Label and ComboBox with items
b.R.Add(out CheckBox c1, "Check").Brush(Brushes.BurlyWood); //CheckBox
b.R.AddButton("Show date", btn1 => { DoDynamicStuff(); }).Width(70).Align("L").Brush(Brushes.Beige); //Button that executes code
b.R.StartStack() //horizontal stack
    .Add<Label>("Close, set ResultButton").Font("Comic Sans MS", size: 18).AddButton("1", 1).Brush(Brushes.Azure).AddButton("2", 2).Brush(Brushes.Bisque) //Label and 2 Buttons that close the dialog and set ResultButton
    .End(); //end stack

b.R.AddOkCancel();

b.End();

b.ShowDialog();

void DoDynamicStuff() {
    if (cal.SelectedDate != null) {
        text1.Text = cal.SelectedDate.ToString();
        DateTime tempdate = (DateTime)cal.SelectedDate;
        tb1.Text = tempdate.ToString("MMM dd, yyyy");
        label1.Content = "Dynamic label";
        label1.Foreground = Brushes.DarkRed;
        label2.Content = "Second label resized";
        label2.FontSize = 18;
        label2.FontFamily = new FontFamily("Brush Script MT");
        label2.Foreground = Brushes.Navy;
        b.Window.Title = "Title changed by button press";
        b.Window.Background = Brushes.Aqua;
    } else {
        text1.Text = "Pick a date, please!";
      }
    if (combo1.SelectedItem.ToString() == "Dialog") {
        dialog.show("You chose the 'Dialog' option.\nDismiss to continue.");
    }
}


Forum Jump:


Users browsing this thread: 1 Guest(s)