wpf - How to change Border color of ComboBox using code? -


i have combobox , want change border's color red mark mandatory field. generating combobox column dynamically through code. properties should set in order change border color?

  datagridtemplatecolumn datagridcomboboxtemplatecolumnobj = new datagridtemplatecolumn();   datagridcomboboxtemplatecolumnobj.header = column.header;   frameworkelementfactory comboboxfactory = new frameworkelementfactory(typeof(combobox));   binding bindingitemsourceobj = new binding(column.itemssourcepropertyname);   comboboxfactory.setvalue(combobox.horizontalalignmentproperty, horizontalalignment.stretch);   comboboxfactory.setvalue(combobox.itemssourceproperty, bindingitemsourceobj);                 comboboxfactory.setvalue(combobox.selectedvaluepathproperty, column.valuepropertyname);    binding selectedvaluebindingobj = new binding(column.propertyname);   selectedvaluebindingobj.mode = bindingmode.twoway;   selectedvaluebindingobj.updatesourcetrigger = updatesourcetrigger.propertychanged;   comboboxfactory.setvalue(combobox.selectedvalueproperty, selectedvaluebindingobj);   datagridcomboboxtemplatecolumnobj.celltemplate = new datatemplate();   datagridcomboboxtemplatecolumnobj.celltemplate.visualtree = comboboxfactory;   datagridcolumnobj = datagridcomboboxtemplatecolumnobj; 

if have combobox:

<combobox x:name="mycombobox"/> 

you can set value of border.borderbrushproperty:

mycombobox.setvalue(border.borderbrushproperty, brushes.red); 

in way change border color of combobox red.

edit: added example specific frameworkelementfactory:

frameworkelementfactory comboboxfactory = new frameworkelementfactory(typeof(combobox)); comboboxfactory.setvalue(border.borderbrushproperty, brushes.red);  controltemplate ct = new controltemplate(typeof(combobox)); ct.visualtree = comboboxfactory; mycombobox.template = ct; 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -