ComponentOne FlexGrid for UWP
Features / Performance Optimization / Incremental Template Updating
In This Topic
    Incremental Template Updating
    In This Topic

    With incremental template updating through the CellContentChanging event, you can update the cell template in phases. This improves load time and scrolling performance because cells can be rendered in parts, or phases, rather than all at once.

    For example, as a user scrolls through the grid very quickly, the cell content might be displayed as plain text. When the grid stops scrolling, the cell content can be updated to display heavier content that requires expensive calculation; content you wouldn't need to have rendered for every cell during a scroll.

    Successive phases can be used to perform heavier actions, and will be executed provided the UI-thread is free. This is modeled after a similar feature from the Microsoft GridView control.

    Note: You can see the CellContentChanging event in action in the Financial sample. In the Control Explorer, it's the See it in action! sample. You can find the FlexGrid samples installed here on your machine:
    Documents\ComponentOne Samples\UWP\C1.UWP.FlexGrid\CS

    The CellContentChanging event resembles the following:

    C#
    Copy Code
    private void _flexFinancial_CellContentChanging(C1FlexGrid sender, CellContentChangingEventArgs args)
    {
        if (args.Phase == 0)
        {
            args.RegisterUpdateCallback(_flexFinancial_CellContentChanging);
        }
        else if (args.Phase == 1)
        {
            var factory = _flexFinancial.CellFactory as FinancialCellFactory;
            if (factory != null)
                factory.ShowLiveData(_flexFinancial, args.Range, args.Cell);
        }
    }
    

    The preceding CellContentChanging sample calls the ShowLiveData event:

    C#
    Copy Code
    public void ShowLiveData(C1FlexGrid grid, CellRange range, FrameworkElement cell)
    {
        var stockTicker = (cell as Border).Child as StockTicker;
        if (stockTicker != null)
        {
            var c = grid.Columns[range.Column];
            var r = grid.Rows[range.Row];
            var pi = c.PropertyInfo;
     
            // to show sparklines
            stockTicker.Tag = r.DataItem;
            stockTicker.BindingSource = pi.Name;
     
            var binding = new Binding { Path = new PropertyPath(pi.Name) };
            binding.Converter = new MyConverter();
            binding.Source = r.DataItem;
            binding.Mode = BindingMode.OneWay;
            stockTicker.SetBinding(StockTicker.ValueProperty, binding);
        }
    }
    

    The StockTicker class used in the event represents a sparkline, which is the heavy part of the implementation. By calling this from the CellContentChanging event, the ShowLiveData event isn't executed until the UI-thread is free.