Posts: 41
Threads: 20
Joined: Mar 2021
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!
Posts: 12,073
Threads: 140
Joined: Dec 2002
// 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);
Posts: 41
Threads: 20
Joined: Mar 2021
06-15-2022, 04:43 PM
(This post was last modified: 06-15-2022, 04:54 PM by netdude78.)
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!