Coloring all cells in a specific Column

4 posts, 0 answers
  1. hamish
    hamish avatar
    44 posts
    Member since:
    Jun 2007

    Posted 22 May 2014 Link to this post

    I want to be able to make ALL cells in specific columns a certain background color. I know I can do this using a custom cell template but the problem is that this is extremely slow as it looks at every single cell and then decides what template to apply. It significantly slowed down the performance even with a grid of only several hundred visible columns. I am wondering whether there is a way to just set an entire column to a specific Background and/or foreground color

    Thank you



  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 23 May 2014 Link to this post

    Hi Hamish,

    Using the CellTemplateSelector is the only solution for the desired scenario. What I can suggest you would be to optimize the applied DataTemplates - avoid using StackPanel inside of them, you can replace it with Grid. Also make sure that the PivotGrid itself is not placed inside of StackPanel (use Grid instead) as the StackPanel measures with infinity and this breaks the virtualization - all of the cell containers will be generated at once. 

    Hope this will help you to optimize the performance.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. hamish
    hamish avatar
    44 posts
    Member since:
    Jun 2007

    Posted 23 May 2014 in reply to Kalin Link to this post

    Thank you for your reply. The following XAML is the cell template that I am applying to cells in selected columns which is causing the slowness. Can you see what I can do to this data template to make it a lot quicker. For example should the grid and text block be fixed widths and heights etc. I would appreciate your help - thanks
    <local:CellTemplateSelector.LightYellowTemplate>
                    <DataTemplate>
                        <Border BorderThickness="1 1 0 0" BorderBrush="LightGray">
                            <Grid Background="LightGoldenrodYellow">
                                <TextBlock Text="{Binding Data,Mode=OneWay}" Margin="4" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </local:CellTemplateSelector.LightYellowTemplate>

  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 27 May 2014 Link to this post

    Hello Hamish,

    The DataTemplate you are applying looks well - it shouldn't be causing the slowness. What I assume is that the custom CellTemplateSelector might slow the process if there is a heavy logic inside (a few for loops for example). So my suggestion is to modify the selector in order to be as simple as possible and to avoid unnecessary heavy processes inside.

    Hope this will help you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top