I recently started developing my very first Windows Phone 8 (WP8) application using C# and XAML and quickly found myself in an impasse: The Visual Studio 2012 (VS2012) toolbox did not contain anything I could identify as a dropdown or combobox control. Yet, the Calendar application on my phone uses such a control for its "How Long" selector amongst others.
When the user taps on the control, it opens to reveal its values. If there are more than five values, it opens full-page. With fewer values, such as when specifying the availability state for the duration of the meeting, the list opens in-place.
That was exactly the functionality I was looking for.
A bit of research sent me in the entirely wrong direction and I started investigating the LongListSelector as a possible replacement for the dropdown control. The LongListSelector is ideal for displaying organized lists of items such as a list of contacts in an address book. While the LongListSelector control supports the use of grouping such as by the first letter of a name, for example, it can also be made to display a flat, ungrouped, list. This was what I thought I was looking for but where I wanted to tap an item and have it be selected, the LongListSelector expected the tap to navigate the user somewhere else as it does when tapping a contact.
Thankfully, the article linked above mentioned that the LongListSelector had been moved from the Windows Phone Toolkit to the Windows Phone SDK. So I investigated the Toolkit and found the ListPicker control. This was exactly what I’d been looking for.
I installed the Windows Phone Toolkit using Nuget as described here but was dismayed to find that, though I could now manually add the control by typing it into the XAML file, it didn’t appear anywhere in the VS2012 toolbox.
Again, I searched for instructions for adding these new controls to the VS2012 toolbox and found these. This helped get me a bit closer but didn’t entirely solve my problem. Here are my revised steps for adding the Toolkit controls to the toolbox. Please refer to the original post for screenshots and for a much more comprehensive description of the process.
- Go to the VS2012 Toolbox tab, right click over General and select Add Tab from the context menu.
- Give a name to the newly created toolbox section.
- Right-click the newly added section and select Choose Itemsà
- This is where my instructions are a bit different. The original poster simply selects the controls and adds them to the section. I never found the ListPicker in any of the Choose Toolbox Items tabs. In order to see it and its toolkit mates, I had to click the Browse button and navigate to the toolkit library located by default in \Documents\Visual Studio 2012\Projects\DataCollector2\packages\WPtoolkit.4.2012.10.30\lib\wp8.
- Click OK. This adds the list of toolkit controls to the "Windows Phone Components" tab. Note that they are conveniently pre-selected.
- Click OK. You now should have the controls in a new section in the toolbox so you can drag and drop to your heart’s content.
Hopefully, this can help save the next person some time!