Behaviors are a great way to encapsulate functionality that can be used in a drag-and-drop environment such as Expression Blend.
Out of the box you get a NavigateToPageAction, but I couldn’t see an easy way to navigate backwards to the previous page using any of the built-in behaviors. I wanted to let the user click on an item in a list, and then have the Phone automatically navigate to the previous page.
So here it is, the world’s simplest behavior:
Once you’ve built this class in your project, if you open your project in Expression Blend you should see the GoBackAction listed in the Behaviors section of the Assets tab. You can then drag the behavior onto a UI element, define the event that should trigger the action, and then when the event occurs you should be automatically navigated backwards.
Unfortunately his code didn’t work on the LongListSelector out of the box because although Colin went out of his way to make it work with any ItemsControl, the LongListSelector is not an ItemsControl. Fortunately his code was well commented, and it was trivial to modify it to work with the LongListSelector.
All the changes are in the OnIsPivotAnimatedChanged method in the ListAnimation class.
Next find the section that starts with the comment “locate the stack panel that hosts the items” and replace the code that follows it (up to and including the for loop) with:
The key is the call to GetItemsWithContainers – the first parameter indicates we only want items that are in view, and the second indicates we want the containers (hence the ContentPresenter type in the foreach).
That’s it – Colin did all the hard work – I just adapted it – all kudos to him.