public partial class getname { ArrayList mylist; public getname() { InitializeComponent(); mylist = listboxload(); lb_page2.ItemsSource = mylist; } private void Button_Click(object sender, RoutedEventArgs e) { try { foreach (String S in lb_page2.Items) { OnReturn(new ReturnEventArgs<string>(S)); } } catch (Exception) { } } private ArrayList listboxload() { return list; } public partial class Page1 { public Page1() { InitializeComponent(); } void Button_Click(object sender, RoutedEventArgs e) { getname pageFunction = new getname(); pageFunction.Return += new ReturnEventHandler<String>(OngetNameReturned); this.NavigationService.Navigate(pageFunction); } public void OngetNameReturned(object sender, ReturnEventArgs<String> e) { lb1_page1.Items.Add(e.Result); } } 

    1 answer 1

    Because the OnReturn call means exiting the page function, the rest of the code simply simply will not be executed by analogy with the usual return from the function.

    If you want to return something, then return all at once.

    C # Page

     public partial class Page1 : Page { ... private void Button_Click(object sender, RoutedEventArgs e) { PageFunction1 pageFunction = new PageFunction1(); pageFunction.Return += new ReturnEventHandler<ArrayList>(OngetNameReturned); this.NavigationService.Navigate(pageFunction); } private void OngetNameReturned(object sender, ReturnEventArgs<ArrayList> e) { var a = e.Result;//какая-то обработка вывода } } 

    C # Page Function

     public partial class PageFunction1 : PageFunction<ArrayList> { ArrayList mylist; public PageFunction1() { InitializeComponent(); mylist = listboxload(); } private void Button_Click(object sender, RoutedEventArgs e) { ReturnEventArgs<ArrayList> ret = new ReturnEventArgs<ArrayList>(); OnReturn(new ReturnEventArgs<ArrayList>(mylist)); } private ArrayList listboxload() { ArrayList list = new ArrayList(); list.Add("1"); list.Add("2"); list.Add("3"); return list; } } 

    XAML

     <PageFunction xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:col="clr-namespace:System.Collections;assembly=mscorlib" x:TypeArguments="col:ArrayList" ... > //Content </PageFunction> 
    • The problem with this PageFunction construct is <List <string >>, the big problem is test19
    • There is no OnReturn method, if you record in this way, whether it is possible to isolate it somehow I don’t know - test19
    • one
      @SOFL, I updated the code to use an ArrayList instead of my List<string> . In addition to the code itself, you will need to tweak the XAML definition of the getname class. The method I understand did not appear due to the inconsistency of the returned parameters in x:TypeArguments="..." - Alex Krass
    • Yes, now it is clear that the collection is being returned, it remains only to correctly display in the control. Thank you - test19
    • 2
      @SOFL ideally you need to master the bindings and use in the mvvm application. The easiest way to work is with the ItemsSource property: MyListBox.ItemsSource = MyArrayList and MyArrayList = MyListBox.ItemsSource as ArrayList . - Alex Krass