Note that there are some explanatory texts on larger screens.

plurals
  1. PONotify ListBox and ListBox Item for CRUD from Background Thread
    text
    copied!<p>I'm working with LINQ/SQL within my WP8 app to manage a collection of items that are shown within a ListBox. Sometimes one these objects is changed by a long runned operation using another DataContext. These changes could be one of the CRUD operations, so objects can be created in the background, too. </p> <p>In iOS there is the NSFetchedResultsController for it or i can use a NSNotification - i'm searching for something similar.</p> <p><strong>update</strong> some code for an updating case</p> <p>I'm fetching my items like this:</p> <pre><code> void loadData() { var items = from r in itemDB.items orderby r.UpdatedAt descending select r; var Items = new ObservableCollection&lt;Item&gt;(items); lstData.ItemsSource = Items; } </code></pre> <p>my listBox looks like this</p> <p></p> <pre><code> &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Margin="10" &gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBox Text="{Binding LocalState}" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>and my background code looks like this:</p> <pre><code>static public void UploadAll() { ThreadPool.SetMaxThreads(1,1); ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc)); } static void ThreadProc(Object stateInfo) { ItemsContext itemsDB = new ItemsContext(ItemsContext.DBConnectionString); var notUploadedItems = (from i in itemsDB.items where !i.LocalState.Equals("server") select i); var Items = new ObservableCollection&lt;Item&gt;(notUploadedItems); foreach (Item a in Items) { a.Save(() =&gt; { Deployment.Current.Dispatcher.BeginInvoke(delegate { a.LocalState = "server"; itemsDB.SubmitChanges(); }); //NOW THE LISTBOX SHOULD BE UPDATED }, (err) =&gt; { }); } } </code></pre> <p>at the <code>//NOW THE LISTBOX SHOULD BE UPDATED</code>comment, the corresponding listbox template should be updated </p> <p>add/delete cases are similar.</p> <p>cheers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload