RadTileView only updating one record at a time

2 posts, 0 answers
  1. Matt
    Matt avatar
    2 posts
    Member since:
    Jun 2016

    Posted 02 Jun Link to this post

    Hello,

     

    I have a program I am creating where the tileview represents a collection of computers, with one tile per computer.  The data that backs this is bound as follows;

    <telerik:RadTileView
        x:Name="radTileView"
        MaximizeMode="ZeroOrOne"
        ColumnWidth="250"
        ItemsSource="{Binding Data, Source={StaticResource context}}"
        ItemTemplate="{StaticResource ItemTemplate}"
        ContentTemplate="{StaticResource ContentTemplate}"
        IsVirtualizing="True"
        RowHeight="250"
        Grid.Column="2"
        Grid.Row="0"
        Margin="8,1,10,10"
        />

    In my ViewModel, Data is an observable collection, like this;

    private ObservableCollection<ImagingData> _imagingData = new ObservableCollection<ImagingData>();
    public ObservableCollection<ImagingData> Data
    {
        get
        {
            return _imagingData;
        }
        set
        {
            _imagingData = value;
            OnPropertyChanged(() => this.Data);
        }
    }

    Data is updated by a timer event that polls a database backend.  If i simply update Data by replacing it, everything works fine, except it makes for a poor UI experience since the pane resets constantly. To make for a better experience, where tiles stay maximized, and stay where you put them, i implemented a sort of delta sync.  When the timer event pops, I call UpdateData() with the UI dispatcher.  UpdateData copies Data to an array, then adds new records, deletes records that are not in scope anymore, and updates fields on records that already exist.  it is a crude proof of concept, but here it is;

    private void UpdateData(ImagingData[] newItems, ImagingData[] existing)
    {
        //var dataArray = _imagingData.ToArray();
        foreach (var item in existing)
        {
            var matchedItem = newItems.Where(c => c.ComputerName == item.ComputerName).FirstOrDefault();
     
            if (matchedItem == null)
                Data.Remove(item);
        }
     
        foreach (var item in newItems)
        {
            var matchedItem = existing.Where(c => c.ComputerName == item.ComputerName).FirstOrDefault();
     
            if(matchedItem == null)
            {
               Data.Add(item);
                return;
            }
     
            matchedItem.ImagingPasses = item.ImagingPasses;
            matchedItem.LastKnownActivity = item.LastKnownActivity;
            matchedItem.ImagingState = item.ImagingState;
        }
     
        OnPropertyChanged("Data");
    }

    The problem I am having that when i use this method, only 1 record is added to the Data collection each time the update timer fires, even though I have confirmed that the update loop does iterate over all the members.  Visually, you see one tile appear, then the next, then the next, etc, separated by one timer iteration.  I have tried all manner of different ways to remedy this but nothing seems to work.

  2. Matt
    Matt avatar
    2 posts
    Member since:
    Jun 2016

    Posted 03 Jun in reply to Matt Link to this post

    Nevermind,  this was a really stupid bug on my part.  After the new record it added, it should be "continue"
    not "return".
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top