WP7 LongListSelector and ListPicker fixes and new features in the latest build
published on: 11/17/2010 | Views: N/A | Tags: WP7Toolkit ListPicker LongListSelector
by WindowsPhoneGeek
Recently Microsoft published an updated version of the wp7 toolkit`s controls which you can find here.
In this post I will cover all about the latest changes in the Windows Phone 7 toolkit "Change Set 57505" November 14, with some important fixes and newly added parts of the public API. Basically there are some significant improvement sin the LongListSelector control and a fix in the ListPicker control.
Note: In the last few days I published several articles about these controls you can use them as a reference:
* "LongListSelector in depth". In the first Part1 I explained the visual structure of the control and all abut the available public API. In Part2 I talked about populating the LongListSelector in different ways.
* "ListPicker in depth" series
In this article I will cover in details what`s new in the latest build for each one of these controls.
ListPicker
Fixes
There are only one fix for this control:
- Ingestion blocker: Back button in expanded mode now switches back to normal mode.
LongListSelector
Fixes
There were some well known problems when using this control that are already fixed. You can take a look at the codeplex discussion here. So the fixes are as follows:
- Pathological cases when calculating animation durations.
- SelectedItem binding updates before SelectionChanged event fires.
- Fixes in ObservableCollection support for adding, clearing and removing.
Additions
Besides fixing some of the major bugs Microsoft decided to add some new functionality as well. Mainly they exposed some public api for groups handling. So the newly added components are:
- Add CloseGroupView, GroupViewOpened event, GroupViewClosing event.
- ScrollToGroup is public.
- GetItemsWithContainers.
- SizeChanged events not update scroll extents.
Note: In the official codeplex page is mentioned that "GetItemsInView" is a newly added method. But actually if you make a reference to the previous release "change set 56962" the method exists. So I suppose that that is some type and the new method is actually GetItemsWithContainers.
Here are some more info about the new methods and events.
New Methods
GetItemsWithContainers(bool·onlyItemsInView,·bool·getContainers)
C#: public ICollection<object> GetItemsWithContainers(bool onlyItemsInView, bool getContainers)
This method is of type ICollection<object>. It is used to return either containers or items for either all items with containers or just the visible ones,as specified by the parameters.
onlyItemsInView - when true,will return values for only items that are in view.
getContainers - when true,will return the containers rather than the items.
ScrollToGroup(object·group)
C#: public void ScrollToGroup(object group)
This method is of type void. It Instantly jump to the selected group "group" is the group to jump to.
CloseGroupView()
C#: public void CloseGroupView()
This method is of type void. It close the group view unconditionally.
New Events
GroupViewOpened
This event will be raised when the group Popup's IsOpen has been set to true.
Example:
selector.GroupViewOpened += new EventHandler<GroupViewOpenedEventArgs>(selector_GroupViewOpened);
void selector_GroupViewOpened(object sender, GroupViewOpenedEventArgs e)
{...}
GroupViewClosing
This event will be raised then the group Popup is about to close.
Example:
selector.GroupViewClosing += new EventHandler<GroupViewClosingEventArgs>(selector_GroupViewClosing);
void selector_GroupViewClosing(object sender, GroupViewClosingEventArgs e)
{...}
That was all about the windows phone 7 LongListSelector and ListPicker updated features in the latest toolkit`s build.
I hope that the article was helpful.
You can also follow us on Twitter @winphonegeek
Comments
Thank you
posted by: Dick Heuser on 11/17/2010 10:01:58 PM
Thank you for these four great articles. I appreciate your clear explanations.
Dick
How to install
posted by: Dick Heuser on 11/17/2010 10:04:12 PM
I currently have the November ToolKit installed. To add these improvements do I download the "Change Set" or the whole Toolkit?
Re:How to install
posted by: winphonegeek on 11/17/2010 10:33:17 PM
In order to get the mentioned fixes you will need to:
1.download change set 57505 from: http://silverlight.codeplex.com/SourceControl/changeset/changes/57505
2.build the Microsoft.Phone.Controls.Toolkit project in the PhoneToolkit solution and you will have the undated assembly.
GroupViewOpenedEventArgs not found
posted by: Ian on 12/15/2010 7:24:22 PM
Hi,
I get a GroupViewOpenedEventArgs not found when trying to use the change-set. I've basically copied the 57505 change-set over the November release.
Thanks.
Ian
RE:GroupViewOpenedEventArgs not found
posted by: winphonegeek on 12/16/2010 4:51:36 PM
I was not able to reproduce the issue. You can once again check your dll Path, may be you are using an old version. Here is a link to the toolkit API: http://silverlight.codeplex.com/SourceControl/changeset/view/57505#1355546
There you can see the GroupViewOpenedEventArgs .
You can find/download a sample project that demonstrate the usage of GroupViewOpenedEventArgs here: "Animating the WP7 LongListSelector group items using transitions"
I hope that this will help you.
Scroll to Selected Group not working
posted by: Dick Heuser on 12/17/2010 10:09:52 PM
I have written to code to create a LongListSelector using the techniques that you show here expect that I am using a GroupingLayer in the Linq. It all works well except that upon return from the Group Panel, the display does not scroll to the selected group. If I use the toolkit from Nov 2, it always scrolls to the top. If I use the toolkit from the Silverlight 57505 patch, it always scrolls to the next to the last group. Do you have any idea where I might have made my mistake? Here is some of my code:
public MainPage()
{
InitializeComponent();
dm = new DataManager();
dm.BuildSampleData();
//longListEvents.ItemsSource = dm.currentRegimenEvents;
var selected = from c in dm.currentRegimenEvents
group c by c.scheduledDateDisplayable into n
select new GroupingLayer<string, RegimenEvent>(n);
longListEvents.ItemsSource = selected;
longListEvents.GroupViewClosing += new EventHandler<GroupViewClosingEventArgs>(longListEvents_GroupViewClosing);
}
void longListEvents_GroupViewClosing(object sender, GroupViewClosingEventArgs e)
{
longListEvents.ScrollToGroup(e.SelectedGroup);
}
<toolkit:LongListSelector x:Name="longListEvents" Background="Transparent" IsFlatList="False"
ItemTemplate="{StaticResource eventsItemTemplate}"
GroupHeaderTemplate="{StaticResource groupHeaderTemplate}"
GroupItemTemplate="{StaticResource groupItemTemplate}"
DisplayAllGroups="False"
ShowListHeader="False"
ShowListFooter="False"
>
<toolkit:LongListSelector.GroupItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Background="Black" />
</ItemsPanelTemplate>
</toolkit:LongListSelector.GroupItemsPanel>
</toolkit:LongListSelector>
Thanks, Dick
RE:Scroll to Selected Group not working
posted by: winphonegeek on 12/20/2010 11:08:44 PM
I noticed that you use:
void longListEvents_GroupViewClosing(object sender, GroupViewClosingEventArgs e)
{
longListEvents.ScrollToGroup(e.SelectedGroup);
}
LongListSelector should automatically scroll to the SelectedGroup. If you are not doing animations or anything other that would require manually scrolling to the selected group you should not need to handle this event. In this post:
we have handled this event so that we can do animation before closing the group view.
Scroll to Selected Group not working
posted by: Dick Heuser on 12/20/2010 11:21:55 PM
I added that "longListEvents.ScrollToGroup(e.SelectedGroup);" in an attempt to get it to scroll to the selected Group but it did not help.
My problem is that it is not automatically scrolling to the selected group. If I use the Nov 2 version of the control, it scrolls to the top when a group is selected from the Group Panel. If I use the updated version of the control, it scrolls to the bottom of the list when a group is selected from the Group Panel. Any idea where I have gone wrong?
Thanks for you help.
Dick
RE:Scroll to Selected Group not working
posted by: winphonegeek on 12/21/2010 5:09:31 PM
Actually the problem is most probably due to the lack of correct override of the Equals method in the GroupingLayer class. If you look at the bellow article again you will notice the following: "Note: I have overridden the Equals(object obj) method."
"http://www.windowsphonegeek.com/articles/wp7-longlistselector-in-depth--part2-data-binding-scenarios"
Here is a sample implementation of the Equals and GetHashCode methods for the GroupingLayer class:
public override bool Equals(object obj)
{
GroupingLayer<TKey, TElement> that = obj as GroupingLayer<TKey, TElement>;
return (that != null) && (this.Key.Equals(that.Key));
}
public override int GetHashCode()
{
return Key.GetHashCode();
}
Scroll to Selected Group not working
posted by: Dick Heuser on 12/23/2010 2:42:38 AM
Yes, that was the problem. Thank you for your help.
Dick
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
