Lambda, embeded events and whatnot

Recently I learned about lambda expressions and events, and I wanted to use it in my app.

Apparently, what I'm doing is wrong, because the app is going crazy after I click the "Read" button.

I'm developing app for Win8 .
The problem in short: The stack of last pages is loading more than one instance of Reader page with random parameter (with random parameter – see the code below) no matter what story I'm selecting.

The code:

FFSubcategory subcategory = //Is inherited from previous page... something something NavigationParameters private void Reload() { await var stories = subcategory.GetListOfStories(); foreach(FFStory story in stories) { UserControls.StoryBox sb = new StoryBox(); // ... sb. Click += (sb, e) => { //... show something, osme menu, something & popup.isOpen = true; var options = //Get the child op popup (ListBox) options.SelectionChanged += (o2, e2) => { //Depending on option do something //if index = 1 this.Frame.Navigate(typeof(Readr), sb.storyRef); // <== Really important line }; }; } } private void PageLoaded(object sender, RoutedEventArgs e) { // ... Reload(); //... } 

How can I replace this messed up embeded event subscription?

Edit: Don't worry about missing kewords/syntax elements in code. I had no access to my project, so I recreated only the basic structure of the class

by MrReynevan2 via /r/csharp

Leave a Reply