c# - Windows Phone ListPicker selectedItem without databinding -
i have listpicker in windows phone 8 app, , wondering i'm doing wrong collect selected item in c#.
here's xaml listpicker.
<toolkit:listpicker x:name="brewmethodlist" horizontalalignment="left" margin="-2,24,0,0" verticalalignment="top" height="127" width="164" borderbrush="#ff162e3e" foreground="black" selectionchanged="brewmethodselectionchange" lostfocus="quantityinputlostfocus" background="#ff5c97bf" > <toolkit:listpickeritem x:name="manual_list" content="manual" background="#ff5c97bf"/> <toolkit:listpickeritem x:name="autodrip_list" content="auto drip" background="#ff5c97bf"/> </toolkit:listpicker>
here's c# trying access selected item.
private void brewmethodselectionchange(object sender, selectionchangedeventargs e) { if (brewmethodlist.selecteditem == manual_list) { brewmethod = manual; } else { brewmethod = auto_drip; } update(); }
this simplified version, throws 'system.nullreferenceexception' , if hover mouse on "brewmethodlist" says null, , same goes hovering mouse on "manual_list."
on behalf of being new, i'm not entirely knowledgeable on databinding, , if should doing let me know, thought manage without (plus i'm not solid on capable of). appreciated! i've read every article find.
try
private void brewmethodselectionchange(object sender, selectionchangedeventargs e) { var brewmethodlist = sender listpicker; if (brewmethodlist.selecteditem == manual_list) { brewmethod = manual; } else { brewmethod = auto_drip; } update(); }
but yes, more better if use mvvm pattern. link should reference, http://msdn.microsoft.com/en-us/magazine/hh852595.aspx
edit: better if don't check through name of controls, once implement mvvm pattern lot cleaner , simpler rather doing behind code. :)
Comments
Post a Comment