Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ComboBox Items from enum
#1
I've found a few generic articles on binding a ComboBox to an enum, but I'm a bit stuck on trying to implement this.  Is there a way in wpfBuilder to call Add().Items() with an enum as a parameter?  I'm already using the enums for building out the rest of the data structure, so it'll save me quite a bit of copy/paste if I can do this.

Thanks!
#2
C# code:
// script ""
using System.Windows.Controls;

var b = new wpfBuilder("Window").WinSize(400);
b.R.Add("Combo", out ComboBox combo1).Items(typeof(DayOfWeek).GetEnumValues());
b.AddOkCancel();
b.End();
if (!b.ShowDialog()) return;
print.it((DayOfWeek)combo1.SelectedItem);
#3
Awesome!

I knew it had to be simple.

I just discovered this is even cooler than I thought... the return type of SelectedValue is actually the enum itself too.  So no enum.Parse or enum.TryParse needed!  Woot!


Forum Jump:


Users browsing this thread: 1 Guest(s)