"类型' System.ArgumentException'的例外;发生在mscorlib.ni.dll"

时间:2015-08-13 07:19:51

标签: c# windows-phone-8

我得到了一个代码可供使用,作为一个初学者,我没有完全理解代码(使用MVVM的Windows Phone 8 Silverlight项目)。代码有这个

 public Dictionary<CeFlix.Entities.Enums.Views, string> PageRouting = new Dictionary<CeFlix.Entities.Enums.Views, string>()
    {
         {CeFlix.Entities.Enums.Views.DashboardPage,"DashboardPage.xaml"},
         {CeFlix.Entities.Enums.Views.LargeBannerDetailPage,"/Views/LargeBannerDetailPage.xaml"},
         {CeFlix.Entities.Enums.Views.ChannelDataPage,"/Views/ChannelDataPage.xaml"},
         {CeFlix.Entities.Enums.Views.ChannelDetailPage,"/Views/ChannelDetailPage.xaml"},
         {CeFlix.Entities.Enums.Views.VideoDetailPage,"/Views/VideoDetailPage.xaml"},
         {CeFlix.Entities.Enums.Views.UserLoginPage,"/Views/UserLoginPage.xaml"},
         {CeFlix.Entities.Enums.Views.UserRegisterPage,"/Views/UserRegisterPage.xaml"},
         {CeFlix.Entities.Enums.Views.UploadVideoDetailPage,"/Views/UploadVideoDetailPage.xaml"},
         {CeFlix.Entities.Enums.Views.FeedBackDetailPage,"/Views/FeedBackDetailPage.xaml"},
        {CeFlix.Entities.Enums.Views.EditProfileDetailPage,"/Views/EditProfileDetailPage.xaml"},
         {CeFlix.Entities.Enums.Views.ChangePasswordPage,"/Views/ChangePasswordPage.xaml"},
         {CeFlix.Entities.Enums.Views.MyPlaylistDetailPage,"/Views/MyPlaylistDetailPage.xaml"},
          {CeFlix.Entities.Enums.Views.SubscriptionDetailPage,"/Views/SubscriptionDetailPage.xaml"},
            {CeFlix.Entities.Enums.Views.SelectedSearchItemVideoPage,"/Views/SelectedSearchItemVideoPage.xaml"},
            {CeFlix.Entities.Enums.Views.CategoryDetailPage,"/Views/CategoryDetailPage.xaml"},
            {CeFlix.Entities.Enums.Views.WatchLiveVideoPage,"/Views/WatchLiveVideoPage.xaml"},
            {CeFlix.Entities.Enums.Views.CommentsPage,"/Views/CommentsPage.xaml"},
            {CeFlix.Entities.Enums.Views.CommentsPage,"/Views/RepliesPage.xaml"}
    };

我在项目中添加了两个页面,我想我可以添加到集合中,所以我在PageRouting中添加了两行这样的

,
            {CeFlix.Entities.Enums.Views.CommentsPage,"/Views/CommentsPage.xaml"},
            {CeFlix.Entities.Enums.Views.CommentsPage,"/Views/RepliesPage.xaml"}

枚举也看起来像这样,最后两行代表我添加的两个新页面

 public enum Views
{
    DashboardPage = 1,
    LargeBannerDetailPage = 2,
    ChannelDetailPage = 3,
    VideoDetailPage = 4,
    ChannelDataPage = 5,
    UserLoginPage = 6,
    UserRegisterPage = 7,
    EditProfileDetailPage = 8,
    FeedBackDetailPage = 9,
    UploadVideoDetailPage =10,
    ChangePasswordPage =11,
    MyPlaylistDetailPage = 12,
    SubscriptionDetailPage =13,
    SelectedSearchItemVideoPage =14,
    CategoryDetailPage = 15,
    WatchLiveVideoPage=16,
    RepliesPage = 17,
    CommentsPage = 18
}

之前我没见过这种编程模式。当我启动应用程序时,会抛出一个异常,说&#34;类型&#39; System.ArgumentException&#39;发生在mscorlib.ni.dll&#34; 我该怎么办?有谁可以帮忙。 我认为这也很重要

public void NavigateToPage(CeFlix.Entities.Enums.Views navigateToView, object navigationParameter)
    {
        string path = PageRouting[navigateToView];

        RootFrame.Navigate(new Uri(path + "?Param=" + navigationParameter, UriKind.Relative));
    }

当我现在删除我添加到PageRouting集合的两行新代码时,它编译得很好,但是我无法导航到刚刚添加的那两个新页面。

1 个答案:

答案 0 :(得分:2)

字典需要使用唯一键,并且您已使用相同的键添加了两个条目 - CommentsPage

这看起来像一个拼写错误,因为您添加了RepliesPage枚举值。应该是这个吗?

{CeFlix.Entities.Enums.Views.CommentsPage,"/Views/CommentsPage.xaml"},
{CeFlix.Entities.Enums.Views.RepliesPage,"/Views/RepliesPage.xaml"}