Beginners binding question RRS feed

  • Question

  • Beginner here so have some patience

    I've implemented my backend (a simple search engine) that essentially on click does a 

    SeachResult searchResult = engine.search(searchCriteria)

    From what tutorials I've read I aim to set the DataContext of the search page to the searchCriteria object and bind the various controls the the corresponding properties of the searchCriteria. I'm a bit confused by multi-selects, however. I noticed that the toolkit has a LongListMultiSelector (is this the way to go, is there even a "native"-multiselector?). I of course need to bind it to a list of all available countries (ItemsSource?) but how should I bind the control to the "selectedCountries" in the searchCriteria object so it gets populated automagically? Can it even be done or do I have to do it manually either in a change handler or when the user clicks the search button?

    Thanks in advance,


    Thursday, November 7, 2013 8:58 AM


  • Hi Nik,

    It's not clear to me what exactly you're trying to bind to what here, so if I'm on the wrong track please clarify.

    The LongListMultiSelector is currently available in the Windows Phone Toolkit and not in the SDK itself. The LongListSelector (non-Multi) is in box.

    You can bind your full collection to it by setting the DataContext either on the control itself or on the Page and let the control inherit it, then bind the ItemsSource to the property with your search results:

                    ItemsSource="{Binding SearchResults}"

    You can bind another control to the LongListMultiSelector's SelectedItems properties and it will populate with the checked off items:

                    ItemsSource="{Binding SelectedItems, ElementName=MyLongListMultiSelector}" 

    Binding to set the SelectedItems is significantly trickier and cannot be done directly: the SelectedItems property is read only so can't be set to the custom collection. I'd either set it's contents from code or write an attached property to bind to my selected collection and have that property programmatically set the selection on the LongListMultiSelector.


    Friday, November 8, 2013 3:37 AM