2017-06-07 24 views
0

私はXamarin-formsを使ってアプリケーションを書いています。 popAsync()を使用してリストを編集しているページから移動すると、前のページのリストを更新して変更を表示したいと考えています。Xamarin - PopAsync()後のリストを更新

私のPopulateMachineSelectionList()は、私のmachineオブジェクトをリストに追加します。

これは、あなたが(リストビューでの)ページAとページBを(つまり、リストビューにバインドさリストを編集)している場合、私はあなたがpageAViewModelを渡すことができると思い、私がこれまで試したものを

protected override void OnAppearing() 
    { 

     PopulateMachineSelectionList(); 
     base.OnAppearing(); 
    } 


    async void PopulateMachineSelectionList() 
    { 
     loadedMachines = await machineSync.GetMachines(); 
     if (loadedMachines.Count() != 0) 
     { 
      machineSelectionList.Clear(); 

      foreach (Machine mach in loadedMachines) 
      { //I have an archive boolean that determines whether or not machines should be shown 
       if (!mach.archived) 
       { 
        Console.WriteLine("Adding: " + mach.name + " to the list template"); 
        machineSelectionList.Add(new ListTemplate(null, mach.name, true, true)); 
       } 
      } 
      Console.WriteLine("Refresh List"); 
      machineList.ItemsSource = machineSelectionList; 

     } 
     machineList.SelectedItem = null; 

    } 
+0

machineList ObservableCollectionはありますか? –

+0

私は手伝っていますが、あなたのシナリオに関する情報はほとんどありません。質問を編集してデータを追加してください。あなたが問題を抱えていること全般について私たちに文脈化してください。 –

答えて

1

をあなたのItemsSourceを設定し、「購読」上にBからのメッセージを送信します。

1

です(それは "リスト"を持っているはずです)をpageBに変更し、それを修正します。 PageA(ObservableCollectionとINPCを使用している場合)を自動的に更新する必要があります。

それ以外の場合は、MessagingCenterを使用できます。おそらくこれは、propertychangedイベントがトリガされます

machineList.ItemsSource.Clear(); 
machineList.ItemsSource.Add(machineSelectionList); 

:ポップ前に、などは、以下のコードを何かを試してみて、再び

1

メインスレッドからmachineList.ItemsSource =に必ず電話してください。

元のItemSourceを無効にして、新しいItemSourceを新しいListに割り当てることもできます。

protected override void OnAppearing() 
{ 

    PopulateMachineSelectionList(); 
    base.OnAppearing(); 
} 


async void PopulateMachineSelectionList() 
{ 
    loadedMachines = await machineSync.GetMachines(); 
    if (loadedMachines.Count() != 0) 
    { 
     machineSelectionList.Clear(); 

     foreach (Machine mach in loadedMachines) 
     { //I have an archive boolean that determines whether or not machines should be shown 
      if (!mach.archived) 
      { 
       Console.WriteLine("Adding: " + mach.name + " to the list template"); 
       machineSelectionList.Add(new ListTemplate(null, mach.name, true, true)); 
      } 
     } 
     Console.WriteLine("Refresh List"); 
     Device.BeginInvokeOnMainThread(() => 
     { 
      machineList.ItemsSource = null; 
      machineList.ItemsSource = new List(machineSelectionList); 
     }); 

    } 
    machineList.SelectedItem = null; 

} 
関連する問題