Windows Phone app calls MapUri() twice when I call NavigateService.Navigate()

拟墨画扇 提交于 2019-12-05 08:54:53

Try hooking up the UriMapper through the XAML of the MainPage using a ViewModel instead of through code.

Some cheat in my code to keep only one event.

    private static string lockUri = "";

    public override Uri MapUri(Uri uri)
    {
        lock (lockUri)
        {
            if (lockUri != uri.ToString())
            {
                lockUri = uri.ToString();
                return null;
            }
        }

        // Your code to route here
    }

that is what I do:

public class AppUriMapper : UriMapperBase
{
    public static bool IsNavigating = false;

    public override Uri MapUri(Uri uri)
    {
        var endUri = uri;

        if (IsNavigating)
        {
            IsNavigating = false;

            //blabla......
        }

        System.Diagnostics.Debug.WriteLine("goto: [origin] {0} [dest] {1}", uri, endUri);

        return endUri;
    }
}

in App.cs:

RootFrame.Navigating += (s, e) =>
        {
            AppUriMapper.IsNavigating = true;
            System.Diagnostics.Debug.WriteLine("goto: [mode] {0}, [uri] {1}", e.NavigationMode, e.Uri);
        };

look ok.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!