c# - Display "Select an item" in Combobox when selectedItem is null -
i have wpf combobox bound list of viewmodel objects. selecteditem null, , combobox display blank.
when selected item null, prefer combobox display "select item" guide user select combobox. sort of way, text boxes contain gray text such "enter user name"
any ideas on how this?
edit:
i ended using suggestion overlay textbox, , change visibility based on value of selecteitem
try this- change itemssource , selectedvalue according code.i showed how can achieve this..
<combobox height="23" name="combobox1" width="120" itemssource="{binding ocstring,mode=twoway,updatesourcetrigger=propertychanged,relativesource={relativesource ancestortype=window}}" selectedvalue="{binding selected,mode=twoway,relativesource={relativesource ancestortype=window},updatesourcetrigger=propertychanged}"> <combobox.style> <style targettype="{x:type combobox}"> <style.triggers> <trigger property="selectedindex" value="-1"> <setter property="template"> <setter.value> <controltemplate> <combobox text="select item" isreadonly="true" iseditable="true" itemssource="{binding ocstring,mode=twoway,updatesourcetrigger=propertychanged,relativesource={relativesource ancestortype=window}}" selectedvalue="{binding selected,mode=twoway,relativesource={relativesource ancestortype=window},updatesourcetrigger=propertychanged}"/> </controltemplate> </setter.value> </setter> </trigger> </style.triggers> </style> </combobox.style> </combobox>
or simply->
<combobox text="select item" isreadonly="true" iseditable="true" itemssource="{binding ocstring,mode=twoway,updatesourcetrigger=propertychanged,relativesource={relativesource ancestortype=window}}" selectedvalue="{binding selected,mode=twoway,relativesource={relativesource ancestortype=window},updatesourcetrigger=propertychanged}"/>
Comments
Post a Comment