GoBackAction–a Windows Phone Behavior to navigate back
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:
[DefaultTrigger(typeof (ButtonBase), typeof (System.Windows.Interactivity.EventTrigger), "Click")]
[DefaultTrigger(typeof (UIElement), typeof (System.Windows.Interactivity.EventTrigger), "MouseLeftButtonDown")]
public class GoBackAction : TriggerAction<FrameworkElement>
{
protected override void Invoke(object parameter)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
if(rootFrame !=null)
{
rootFrame.GoBack();
}
}
}
[DefaultTrigger(typeof (UIElement), typeof (System.Windows.Interactivity.EventTrigger), "MouseLeftButtonDown")]
public class GoBackAction : TriggerAction<FrameworkElement>
{
protected override void Invoke(object parameter)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
if(rootFrame !=null)
{
rootFrame.GoBack();
}
}
}