Note that there are some explanatory texts on larger screens.

plurals
  1. POListbox not always adding item using Windows Azure MobileServiceCollection with WP8
    primarykey
    data
    text
    <p>I'm using Windows Azure Mobile Services to store and retrieve data in my Windows Phone 8 app. This is a bit of a complicated issue so I will do my best to explain it.</p> <p>Firstly I'm using raw push notifications to receive a message and when it receives the message it updates a listbox in my app. When I open my app, navigate to the page with the <code>ListBox</code> and receive a push notification the <code>ListBox</code> updates fine. If I press back, then navigate to the same page with the <code>ListBox</code>, the push notification is received, the code to update the <code>ListBox</code> executes with no errors yet the <code>ListBox</code> doesn't update. I have checked that the same code runs using the <code>OnNavigatedTo</code> handler in both scenarios, but it seems like the <code>ListBox</code> does not bind correctly in the second instance when I press back and then re-navigate to the same page. Here are some code snippets:</p> <p>MobileServiceCollection declarations:</p> <pre class="lang-cs prettyprint-override"><code>public class TodoItem { public int Id { get; set; } [JsonProperty(PropertyName = "text")] public string Text { get; set; } } private MobileServiceCollection&lt;ToDoItem, ToDoItem&gt; TodoItems; private IMobileServiceTable&lt;TodoItem&gt; todoTable = App.MobileService.GetTable&lt;TodoItem&gt;(); </code></pre> <p>Push Notification Received Handler:</p> <pre class="lang-cs prettyprint-override"><code>void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e) { string message; using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body)) { message = reader.ReadToEnd(); } Dispatcher.BeginInvoke(() =&gt; { var todoItem = new TodoItem { Text = message, }; ToDoItems.Add(todoItem); } ); } </code></pre> <p>I have tried using:</p> <pre class="lang-cs prettyprint-override"><code>ListItems.UpdateLayout(); </code></pre> <p>and</p> <pre class="lang-cs prettyprint-override"><code>ListItems.ItemsSource = null; ListItems.ItemsSource = ToDoItems; </code></pre> <p>before and after the code in the above procedure that adds the <code>ToDoItem</code> but it didn't help.</p> <p>The following procedure is called in my <code>OnNavigatedTo</code> event handler, and refreshes the <code>Listbox</code> and assigns <code>ToDoItems</code> as the items source:</p> <pre class="lang-cs prettyprint-override"><code>private async void RefreshTodoItems() { try { ToDoItems = await todoTable .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK); } ListItems.ItemsSource = ToDoItems; } </code></pre> <p>The above procedure is <code>async</code> but I have made sure it completes before receiving any notifications. Even so, as mentioned above when I open the app, navigate to the page that shows the <code>ListBox</code> it updates fine. When I press back, navigate to the same page again, it doesn't work. When I back out of the app, re-open it, navigate to the page with the <code>ListBox</code>, it works again, and then fails if I press back and re-open the page. So it seems the <code>ListBox</code> is not binding to <code>ToDoItems</code> correctly when I press back and navigate to the same page.</p> <p>Any help appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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