C# 带有数据模板的无限滚动错误

C# 带有数据模板的无限滚动错误,c#,windows-phone-8,windows-phone,longlistselector,C#,Windows Phone 8,Windows Phone,Longlistselector,在用户获得longlistselector ItemImplemented的结尾后,事件触发items添加成功。但是对于添加的项目,按钮的标记是空的,对于我第一次获得的项目,按钮的标记不是空的 这是我的xaml数据模板: 谢谢。此时可能尚未设置标签。尝试使用Dispatcher将需要标记的代码推迟到以后。DispatcherPriority应该放在低于DataBind的位置。很抱歉,我已经修复了该错误。谢谢。你应该在回答中添加细节。你可以结束这一切。 <DataTemplate x:Key

在用户获得longlistselector ItemImplemented的结尾后,事件触发items添加成功。但是对于添加的项目,按钮的标记是空的,对于我第一次获得的项目,按钮的标记不是空的

这是我的xaml数据模板:


谢谢。

此时可能尚未设置标签。尝试使用Dispatcher将需要标记的代码推迟到以后。DispatcherPriority应该放在低于DataBind的位置。很抱歉,我已经修复了该错误。谢谢。你应该在回答中添加细节。你可以结束这一切。
<DataTemplate x:Key="TitleSongDataTemplate" x:Name="Titledata">
        <Border Background="{StaticResource PhoneForegroundBrush}" Margin="0,0,12,12">
            <Grid  x:Name="GridOfButtons" Background="{StaticResource PhoneForegroundBrush}" >
                <Grid Margin="0, -6, -7, 0"
                      HorizontalAlignment="Right"
                      VerticalAlignment="Top" Height="81" Width="83">
                    <Button 
                        Content="&#xe109;" 
                        FontFamily="Segoe UI Symbol" 
                        Style="{StaticResource RoundButton}" 
                        x:Name="AddToMySongsButton"
                        Tag="{Binding Song}"
                        Background="{StaticResource PhoneBackgroundBrush}"
                        Click="AddToMySongsButton_Click"/>
                </Grid>
                <Grid                          
                      VerticalAlignment="Top"
                      HorizontalAlignment="Left"
                      Margin="-17,-6,0,0" Height="81" Width="95">
                    <Button FontFamily="Segoe UI Symbol"                             
                        Content="&#xe102;"
                        Style="{StaticResource RoundButton}" Margin="10,0,0,0"
                        x:Name="PlayButton"                            
                        Background="{StaticResource PhoneBackgroundBrush}"
                        Tag="{Binding Song}"                            
                        Click="PlayButton_Click"/>
                </Grid>
                <Grid
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Margin="69,-7,60,0" Height="82" Width="84">
                    <Button Style="{StaticResource RoundButton}"
                        Content="&#xe118;" 
                        FontFamily="Segoe UI Symbol"
                        x:Name="DownloadButton"                            
                         Margin="-5,0,0,0"
                         Background="{StaticResource PhoneBackgroundBrush}"
                        Tag="{Binding Song}"
                        Click="DownloadButton_Click"/>
                </Grid>
                <StackPanel VerticalAlignment="Bottom">
                    <TextBlock Text="{Binding Title}"  Foreground="{StaticResource PhoneBackgroundBrush}" Margin="6 , 4, 6, 4"/>
                    <TextBlock Text="{Binding Artist}" Foreground="Gray" Opacity="0.75" Margin="6, 0, 0, 6"/>
                </StackPanel>
            </Grid>
        </Border>
    </DataTemplate>
<phone:Pivot x:Name="MainTitle">            
        <phone:PivotItem Header="Rock">
            <Grid>
                <phone:LongListSelector x:Name="RockLongList"
                    GridCellSize="220,150"
                LayoutMode="Grid"
                ItemTemplate="{StaticResource TitleSongDataTemplate}"
                ItemRealized="RockLongList_ItemRealized"/>
                <TextBlock x:Name="RockText"
                           Text="Загрузка..." 
                           FontSize="60"
                           Opacity="0.5"
                           Style="{StaticResource LongListSelectorGroupHeaderLetterTileStyle}" 
                           Margin="0,10,10,10"                               
                           TextWrapping="Wrap" 
                           HorizontalAlignment="Right" 
                           Width="436"/>
            </Grid>
        </phone:PivotItem>
private void RockLongList_ItemRealized(object sender, ItemRealizationEventArgs e)
    {
        var nownum = offset + 50;
        if (nownum >= usercount)
        {
            MainTitle.Title = "All songs've downloaded";
        }
        else
        {
            SpecialSongs.SongJSON song = e.Container.Content as SpecialSongs.SongJSON;
            if (song != null)
            {
                int myoffset = 2;
                // Only if there is no data that is currently getting loaded would be initiate the loading again
                if (!isCurrentlyLoading && defaultBindList.Count - defaultBindList.IndexOf(song) <= myoffset)
                {
                    LoadDataFromSource();
                }
            }
        }
    }
private void LoadDataFromSource()
    {
        this.Dispatcher.BeginInvoke(() =>
        {
            MainTitle.Title = "Downloading test...";
        });
        //progressBar.IsVisible = true;
        isCurrentlyLoading = true;
        string UsersUri = string.Format("https://api.vk.com/method/audio.get?&count=50&access_token={0}&user_id={1}&version=4.92&offset={2}", AccessToken, uID, offset);
        //var query = string.Format(datasourceUrl, currentPage);
        WebClient client = new WebClient();
        client.DownloadStringCompleted += client_DownloadStringCompleted;
        client.DownloadStringAsync(new Uri(UsersUri));
    }

    private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        //Here handle exception
        using (var reader = new MemoryStream(Encoding.Unicode.GetBytes(e.Result)))
        {
            SpecialSongs songs = JsonConvert.DeserializeObject<SpecialSongs>(e.Result);
            this.Dispatcher.BeginInvoke(() =>
            {
                foreach (var tracks in songs.songs)
                {
                    rockBindList.Add(tracks);                        
                    MainTitle.Title = "Downloaded test...";
                }
                RockLongList.ItemsSource = rockBindList;
                isCurrentlyLoading = false;
                //progressBar.IsVisible = false;
            });
          }
          offset += 50;
      }
private void DownloadButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            SpecialSongs.SongJSON songdgd = (SpecialSongs.SongJSON)(sender as Button).Tag;
            this.Download.Message = songdgd.Artist + "\n" + songdgd.Title;
            string StringToSave = "shared/transfers/" + songdgd.Artist + songdgd.Title;
            var linktosave = StringToSave.Replace(" ", "");
            transferRequest = new BackgroundTransferRequest(new Uri(songdgd.URI, UriKind.RelativeOrAbsolute)) { Method = "GET" };
            var uri = new Uri(linktosave, UriKind.Relative);
            songdgd.URI = linktosave.Replace("shared/transfers/", "");
            var json = JsonConvert.SerializeObject(songdgd);
            var name = linktosave.Replace("shared/transfers/", "");
            transferRequest.Tag = "json" + json + "json" + "uri" + name + "uri";
            transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
            transferRequest.DownloadLocation = uri;
            try
            {
                BackgroundTransferService.Add(transferRequest);
            }
            catch
            {
                MessageBox.Show("Эта песня уже загружается.");
            }
        }
        catch { MessageBox.Show("Error while downloading"); }
    }