Friday, April 15, 2016

RegionManager.RequestNavigate is not working!

This is not so much a solution, but a debugging hint.

Recently I was banging my head for hours on a RequestNavigate not working. After a lot of googling and head banging, I found out that RequestNavigate has a callback and it has useful error information that can help in determining the issue.

The signature is: public static void RequestNavigate(this IRegionManager regionManager, string regionName, Uri source, Action navigationCallback)

And here is how you can use it:

_regionManager.RequestNavigate(RegionNames.MainRegion, uri, nr =>
{
if (nr.Result.HasValue && nr.Result == false)
{
//put a breakpoint in here to determine why. nr.Error will have the data
var error = nr.Error;
}
});

In my case, I found out that the caller was on a background thread and hence, the navigation was failing silently. By subscribing to my event on the UI thread, I was able to solve my issue!

No comments: