c# - ComboBox Won't Change Item Displayed -
so follow tutorial link it's tutorial allow spaces in combo boxes itemssource list of enum. tutorial worked , explained well. issue i'm having , wondering if help, when choose display lets software engineer , later decide should team lead not change. remains software engineer, i'm wondering how abouts fix this?
namespace caliburnmicrodemo1 { public class enumhelper : dependencyobject { public static type getenum(dependencyobject obj) { return (type)obj.getvalue(enumproperty); } public static void setenum(dependencyobject obj, string value) { obj.setvalue(enumproperty, value); } // using dependencyproperty backing store enum. enables animation, styling, binding, etc... public static readonly dependencyproperty enumproperty = dependencyproperty.registerattached("enum", typeof(type), typeof(enumhelper), new propertymetadata(null, onenumchanged)); private static void onenumchanged(dependencyobject sender, dependencypropertychangedeventargs e) { var control = sender itemscontrol; if (control != null) { if (e.newvalue != null) { var _enum = enum.getvalues(e.newvalue type); control.itemssource = _enum; } } } public static bool getmoredetails(dependencyobject obj) { return (bool)obj.getvalue(moredetailsproperty); } public static void setmoredetails(dependencyobject obj, bool value) { obj.setvalue(moredetailsproperty, value); } // using dependencyproperty backing store moredetails. enables animation, styling, binding, etc... public static readonly dependencyproperty moredetailsproperty = dependencyproperty.registerattached("moredetails", typeof(bool), typeof(enumhelper), new propertymetadata(false, onmoredetailschanged)); private static void onmoredetailschanged(dependencyobject sender, dependencypropertychangedeventargs e) { var control = sender frameworkelement; if (control != null) { var enumobject = control.datacontext; var fieldinfo = enumobject.gettype().getfield(enumobject.tostring()); var array = fieldinfo.getcustomattributes(false); if (array.length == 0) { if (control textblock) { ((textblock)control).text = enumobject.tostring(); } else if (control contentcontrol) { ((contentcontrol)control).content = enumobject; } return; } foreach (var o in array) { if (o descriptionattribute) { control.tooltip = ((descriptionattribute) o).description; } else if (o displayattribute) { if (control textblock) { ((textblock) control).text = ((displayattribute) o).name; } else if (control contentcontrol) { ((contentcontrol)control).content = ((displayattribute)o).name; } } } } } } } enum: public enum designation { [display(name="software engineer")] [description("software engineer responsible core development.")] softwareengineer, [display(name = "team lead")] [description("team lead responsible leading small team of 5 10 members.")] teamlead, [display(name = "product manager")] [description("product manager responsible core management.")] productmanager }
Comments
Post a Comment