units of measurement - WPF: Editable ComboBox and StringFormat -


(first of all, simplified sample understand.)

i want editable combobox shows values in inches. the original (source) value value in pixels (dips), because unit in application works internally. user shouldn't see value in pixels, in inches (the measurement unit of ui). determined must use converter translate pixels inches , viceversa.

the combobox items should formatted "{0} in".

it should appear

[ 4 in  |v]   [ 1 in  ]   [ 2 in  ]   [ 3 in  ]   [ 4 in  ] 

but, remember, internally should work in pixels! , editable. works part. have been totally unable achieve this.

i have far:

  <combobox iseditable="true"             itemstringformat="'{}{0} in}'"                               text="{binding relativesource={relativesource self}, path=selectedvalue, mode=twoway, converter={staticresource mypixeltoinchesconverter}, stringformat='{}{0} in}'}">             <system:double>1</system:double>             <system:double>2</system:double>             <system:double>3</system:double>   </combobox> 

the problem? when select item, it's not formatted. , when write number in editable region of combobox, it's not formatted, too.

so, best way combobox format items when user enters non-existent value??

thanks!

probably bit late, found setting text property use binding can work, bit of kludge. in case working currency value, same principles should apply

text = {binding path=indemnity, stringformat=c0} 

however, entering text value not in list still exhibits problem stringformat not applied (for strange reason known ms folks designed this).

to work around this, added lostfocus handler writes incorrect value, followed writing correct value again - @ stage stringformat applied:

private void indemnitycombo_lostfocus(object sender, routedeventargs e) {     var vm = this.datacontext ratesviewmodel;    // view model class     if (vm != null) {         decimal indemnity = vm.indemnity;         vm.indemnity = indemnity + 1m;         vm.indemnity = indemnity;     } } 

it's not elegant, job me. hope can useful other users.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -