简体   繁体   English

WP8数据绑定中的无法刷新longlistselector

[英]Cant refresh longlistselector in WP8 Databinding

I'm having some trouble with databinding to a LongListSelector. 我在将数据绑定到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. 问题是当我按下刷新按钮时,我的应用会获取一个新的JSON feed,对其进行解析并尝试将其绑定。 My app seems to download the JSON and stuff, but doesn't refresh the UI. 我的应用似乎下载了JSON和其他内容,但没有刷新UI。 Where have I gone wrong? 我哪里出问题了?

I've tried BoardLongList.ItemsSource = null; 我试过BoardLongList.ItemsSource = null; and BoardLongList.ItemsSource.Clear(); BoardLongList.ItemsSource.Clear(); to no avail. 无济于事。

Any ideas? 有任何想法吗? The JObject is from newtonsoft.json and the RootObject is from ViewModels.RootObject. JObject来自newtonsoft.json,而RootObject来自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: 我的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>

Is your ItemsSource an ObservableCollection?. 您的ItemsSource是ObservableCollection吗? ObservableCollection is collection with notification that when something is changed in the collection, it notifies the UI. ObservableCollection是具有通知的集合,当集合中的某些内容发生更改时,它会通知UI。

Make obj.Movements an ObservableCollection 将obj.Movements设为ObservableCollection

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). 您可以使用ItemRealized事件并使用ListHeader (或ListFooter从底部拉出)来完成此操作。 Within the ItemRealized event you check if the item is your header object. 在ItemRealized事件中,您检查项目是否为标题对象。 If it is then load more items. 如果是,则加载更多项目。

Hope it helps. 希望能帮助到你。

I finally figured it out. 我终于弄明白了。 It was because of C# web caching my request. 这是因为C#Web缓存了我的请求。 Not because of my databinding! 不是因为我的数据绑定!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM