user2490629
user2490629

Reputation: 231

Access Violation Exception while accessing BackStack

I have a page named Page1.xaml and can access and be accessed from Page2.xaml and Page3.xaml. I don't want to turn back from Page1 to Page3 and just to Page2.

Now when I do this an exception occurs:

if (this.NavigationService.BackStack.Any())
{

}

it is:Attempted to read or write protected memory.

Can someone please show me how can I simply do what I said above to work for both WP7 and WP8 (the msdn documentation talks about here and there, so I miss the point.)

Update: when I use NavigationService.CanGoBack the same error occurs: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Upvotes: 1

Views: 201

Answers (1)

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

If you just want to know if there are items on the BackStack then you should use the CanGoBack property of the NavigationService.

if(NavigationService.CanGoBack)
{
    // logic
}

If you want to remove all of the entries of the BackStack then use the RemoveBackEntry method.

while (NavigationService.CanGoBack) 
{
    NavigationService.RemoveBackEntry();
}

Upvotes: 1

Related Questions