c# - WPF : Close combobox on item selection and display Message box -
goal have combobox in wpf , whenever user selects item combobox want close combobox (displaying old value selected value) , display messagebox ok/cancel button. if user clicks ok, new selected value should set else should return.
problem when i'm selecting item i'm able display messagebox along combobox open, dont want. user selects want close combobox , display messagebox.
how can it?
xmal code
<combobox name="currency" grid.row="1" grid.column="5" itemssource="{binding comboboxsource}" selectedvaluepath="value.bank_currency" isreadonly="false" istextsearchenabled="true" textsearch.textpath="value.bank_currency" selecteditem="{binding selectedbankcurrency, updatesourcetrigger=lostfocus,mode=twoway}"> c# code
public keyvaluepair<string, bankcurrencyobject>? selectedbankcurrency { { return _selectedcurrency; } set { messageboxresult result = messagebox.show("are sure want change currency?", "warning", messageboxbutton.okcancel, messageboximage.question); if (result == messageboxresult.cancel) { return; } else { //set values } } } attempt using selectionchanged event did not work,
private void combobox_selectionchanged(object sender, selectionchangedeventargs e) { if (datacontext == null) return; var combo = (sender combobox); if (combo != null && combo.isdropdownopen) { combo.isdropdownopen = false; var binding = combo.getbindingexpression(combobox.selecteditemproperty); binding.updatesource(); binding.updatetarget(); } }`
you can span task on .net thread pool , display message box through dispatcher.
Comments
Post a Comment