Reputation: 229
I was given a code to work on, as a beginner I didn't fully understand the code (a windows phone 8 Silverlight project using MVVM). the code has this
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"}
};
I added two more pages to the project and I thought I could just add to the collection so I added two lines like this inside the PageRouting
,
{CeFlix.Entities.Enums.Views.CommentsPage,"/Views/CommentsPage.xaml"},
{CeFlix.Entities.Enums.Views.CommentsPage,"/Views/RepliesPage.xaml"}
The enum also looks like this, the last two lines represent the two new pages I added
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
}
I had not seen this programming patter before. When I launch the App I an exception is thrown that say "An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll" what do I do? can anyone help. I think it's important I post this too
public void NavigateToPage(CeFlix.Entities.Enums.Views navigateToView, object navigationParameter)
{
string path = PageRouting[navigateToView];
RootFrame.Navigate(new Uri(path + "?Param=" + navigationParameter, UriKind.Relative));
}
When I now remove the two new lines of code I added to the PageRouting collection, it compiles fine, but I'm not able to navigate to those two new pages I just added.
Upvotes: 0
Views: 3853
Reputation: 26213
A dictionary requires unique keys, and you've added two entries with the same key - CommentsPage
.
This looks like a typo, as you've added a RepliesPage
enum value. Should it be this?
{CeFlix.Entities.Enums.Views.CommentsPage,"/Views/CommentsPage.xaml"},
{CeFlix.Entities.Enums.Views.RepliesPage,"/Views/RepliesPage.xaml"}
Upvotes: 2