c# - How to work with down arrow key in Auto Suggest Box? -
in auto suggest box when pressing down arrow in suggestion list suggestion list getting closed automatically in no time.
i want keep open list until user presses enter key. xaml code
<autosuggestbox x:name="recipient" keyup="recipient_keydown" fontsize="18" height="50" textchanged="recipient_textchanged" suggestionchosen="recipient_suggestionchosen" x:uid="recipienttextplaceholder" horizontalalignment="left" background="white" verticalalignment="center" margin="30,20,0,0" style="{staticresource autosuggestboxstyle2}"> <autosuggestbox.itemtemplate> <datatemplate> <grid> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition/> <columndefinition/> </grid.columndefinitions> <textblock text="{binding firstname}" grid.column="0" x:name="firstname" visibility="{binding firstname, converter={staticresource nullorwhitespaceconverter}}" textalignment="left"/> <textblock text="|" grid.column="0" margin="0,0,-10,0" visibility="{binding visibility,elementname=middlename}" horizontalalignment="right"/> <textblock text="{binding middlename}" margin="10,0,0,0" visibility="{binding middlename, converter={staticresource nullorwhitespaceconverter}}" x:name="middlename" grid.column="1" textalignment="left"/> <textblock text="|" grid.column="1" visibility="{binding visibility,elementname=lastname}" margin="0,0,-6,0" horizontalalignment="right"/> <textblock text="{binding lastname}" margin="10,0,0,0" x:name="lastname" visibility="{binding lastname, converter={staticresource nullorwhitespaceconverter}}" grid.column="2" textalignment="left"/> <!--<textblock text="|" grid.column="2" margin="0,0,-6,0" visibility="{binding visibility,elementname=lastname}" horizontalalignment="right"/>--> </grid> </datatemplate> </autosuggestbox.itemtemplate> </autosuggestbox>
textchanged event:
private void recipient_textchanged(autosuggestbox sender, autosuggestboxtextchangedeventargs args) { if (sender.text.length == 0) { recipient.itemssource = new list<string>(); return; } var recipientfilteredbypersondata = new list<table_people>(); var recipientfilteredbyplace = new list<table_places>(); if (peoplelist != null) { foreach (var item in peoplelist) { if (item.firstname.contains(sender.text, stringcomparison.ordinalignorecase) || item.middlename.contains(sender.text, stringcomparison.ordinalignorecase) || item.lastname.contains(sender.text, stringcomparison.ordinalignorecase)) { item.icon = "../assets/user_profile.png"; recipientfilteredbypersondata.add(item); } } cvrbyperson.source = recipientfilteredbypersondata.orderby(x => x.firstname).groupby(x => x.firstname[0]).tolist(); //recipient.itemssource = recipientfilteredbypersondata; } if (placeslist != null) { foreach (var item in placeslist) { if (item.accountnumber.contains(sender.text, stringcomparison.ordinalignorecase) || item.name.contains(sender.text, stringcomparison.ordinalignorecase)) { item.icon = "../assets/ic_location.png"; recipientfilteredbyplace.add(item); } } cvrbyplace.source = recipientfilteredbyplace.orderby(x => x.firstname).groupby(x => x.firstname[0]).tolist(); //recipient.itemssource = recipientfilteredbyplace; } list<object> combineplaceperson = (from x in recipientfilteredbypersondata select (object)x).tolist(); combineplaceperson.addrange((from x in recipientfilteredbyplace select (object)x).tolist()); if (combineplaceperson.count == 0) { var noresults = new list<table_people>(); var resultwithnoitem = new table_people { firstname = "no results." }; noresults.add(resultwithnoitem); recipient.itemssource = noresults; } else { recipient.itemssource = combineplaceperson; } }
suggestion chosen event:
private void recipient_suggestionchosen(autosuggestbox sender, autosuggestboxsuggestionchoseneventargs args) { var gettype = args.selecteditem.gettype(); if (gettype.name == "table_people") { var selecteditemrecipient = args.selecteditem table_people; sender.text = selecteditemrecipient.firstname + " " + selecteditemrecipient.lastname; recipienterror.visibility = visibility.collapsed; _personid = selecteditemrecipient.personid; } else { var selecteditemrecipientplaces = args.selecteditem table_places; _placeid = selecteditemrecipientplaces.placeid; sender.text = selecteditemrecipientplaces.firstname + " " + selecteditemrecipientplaces.lastname; recipienterror.visibility = visibility.collapsed; } }
i setting itemssource code.do need handle keup event or not?
private void recipient_keyup(object sender, keyroutedeventargs e) { if (e.key == windows.system.virtualkey.down) { recipient.issuggestionlistopen = true; } }
thanks in advance.
that might you. used on windows forms combobox
private void combobox1_keydown(object sender, keyeventargs e) { if (e.keycode == keys.down) messagebox.show("hello"); }
Comments
Post a Comment