Reputation: 1037
I'm having some trouble with databinding to a LongListSelector. When I initally run this method, it works. The data is binded and everything is good.
The problem is when I press the refresh button, my app fetches a new JSON feed, parses it and tries to bind it. My app seems to download the JSON and stuff, but doesn't refresh the UI. Where have I gone wrong?
I've tried BoardLongList.ItemsSource = null;
and BoardLongList.ItemsSource.Clear();
to no avail.
Any ideas? The JObject is from newtonsoft.json and the RootObject is from ViewModels.RootObject.
Thanks in advance!
private void Bind(JObject rootObject)
{
string rootObjectString = rootObject.ToString();
RootObject obj = JsonConvert.DeserializeObject<RootObject>(rootObjectString);
// Bind to LongListSelector
BoardLongList.ItemsSource = obj.Movements;
}
My XAML:
<phone:LongListSelector Grid.Row="1" x:Name="BoardLongList" Margin="0,0,-12,1" ItemsSource="{Binding Movement}">
<phone:LongListSelector.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="2" Height="50">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="120" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding A1}" />
<TextBlock Grid.Column="1" Text="{Binding A2}" />
<TextBlock Grid.Column="2" Text="{Binding A3}" />
<TextBlock Grid.Column="3" Text="{Binding A4}" />
</Grid>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Upvotes: 0
Views: 149
Reputation: 1037
I finally figured it out. It was because of C# web caching my request. Not because of my databinding!
Upvotes: 0
Reputation: 9434
Did you try the pull to refresh feature?
Check this out!
You can accomplish this with the ItemRealized event and using a ListHeader(or ListFooter to pull from bottom). Within the ItemRealized event you check if the item is your header object. If it is then load more items.
Hope it helps.
Upvotes: 0
Reputation: 222582
Is your ItemsSource an ObservableCollection?.ObservableCollection
is collection with notification that when something is changed in the collection, it notifies the UI.
Make obj.Movements an ObservableCollection
Upvotes: 1