好的。终于设法让它工作了。所以,将它发布在这里,因为我很确定会有一个像我一样迷失的灵魂会欣赏这个答案。
要在 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;
}
}
希望这将有助于任何尝试在 WP8 中使用 Caliburn Micro 实现 Uri/文件关联的人。