0

我对 ÆØÅ 有意见。如果我尝试导航到其中一个,我会得到 system.object 而不是我的视图。

unity.RegisterTypeForNavigation();

public static void RegisterTypeForNavigation<T>(this IUnityContainer container)
{
    container.RegisterType(typeof(object), typeof(T), typeof(T).FullName);
}

我应该转义 FullName 吗?

4

1 回答 1

0

是的,您应该对类型名称 fx 进行 url 编码。像这样

public static class UnityExtensions
{
    public static void RegisterTypeForNavigation<T>(this IUnityContainer container)
    {
        container.RegisterType(typeof(object), typeof(T),Replace(typeof(T).FullName));
    }

    public static string Replace(string url)
    {
        return WebUtility.UrlEncode(url);
    }
}

而且您还必须在导航时进行 urlencode。

public void Navigate(object navigatePath, string region = RegionNames.ContentRegion,
                         NavigationParameters parameters = null,
                         Action<NavigationResult> navigationCallback = null)
    {
        if (navigatePath == null) return;

        var path = UnityExtensions.Replace(navigatePath.ToString());

        if (parameters == null)
            _regionManager.RequestNavigate(region, path);
        else
        {
            var uri = new Uri(path, UriKind.RelativeOrAbsolute);
            if (navigationCallback == null)
                _regionManager.RequestNavigate(region, uri, parameters);
            else
                _regionManager.RequestNavigate(region, uri, navigationCallback, parameters);
        }
    }

而已

于 2015-06-25T15:51:14.377 回答