用于Caliburn Micro的RootFrame UriMapper

时间:2013-04-15 14:01:28

标签: windows-phone-8 oauth-2.0 caliburn.micro

我一直在谷歌搜索如何实际实现这一点无济于事。无法找到有关如何使用Caliburn Micro实际执行此操作的单一资源。

基本上,我正在尝试这个http://www.developer.nokia.com/Community/Wiki/OAuth_on_Windows_Phone

在示例中,它使用redirect_uri作为普通链接。我是通过协议/文件关联完成的(参考http://www.developer.nokia.com/Community/Wiki/URI_associations_for_Windows_Phone_8)。一切正常。我在没有Caliburn Micro的情况下开始工作。

但基于该示例,我需要实施UriMapperBase并将其分配给RootFrame.UriMapper

我的问题是如何使用CaliburnMicro为WP8实现UriMapper。对于Win 8,它是不同的,因为我可以覆盖OnActivate并检查ActivationKind.Protocol并且不需要UriMapper

1 个答案:

答案 0 :(得分:3)

确定。终于设法让它发挥作用。因此,我会在这里发布,因为我很确定会像我一样会失去灵魂,他会很欣赏这个答案。

要在Caliburn中使用UriMapper,您需要覆盖CreatePhoneApplicationFrame中的bootsrapper

Boostrapper.cs

protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
{
    // var frame = base.CreatePhoneApplicationFrame(); this doesnt work
    var frame = new PhoneApplicationFrame(); // this works
    frame.UriMapper = new AssociationUriMapper();

    return frame;
}

AssociationUriMapper.cs - 我按照上面的链接

跟踪了示例
public class AssociationUriMapper : UriMapperBase
{
    private string tempUri;


    public override Uri MapUri(Uri uri)
    {
        tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

        // URI association launch for contoso.
        if (tempUri.Contains("pocketthis:MainPage"))
        {
            // Get the category ID (after "CategoryID=").
            //int categoryIdIndex = tempUri.IndexOf("CategoryID=") + 11;
            //string categoryId = tempUri.Substring(categoryIdIndex);

            // Views/MainPage.xaml returns external exception, 
            // so remember the / before views
            return new Uri("/Views/MainPage.xaml", UriKind.Relative);
        }

        // Otherwise perform normal launch.
        return uri;
    }
}

希望这有助于任何尝试使用Caliburn Micro在WP8中实现Uri / File Association的人。

相关问题