Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2145
XamDataGrid User Defined Header Color
posted

Hello Team,

We have an issue with xamdatagrid that we are struggling with and decided to ask for help.

We use the xamdatagrid to display and edit large amounts of data, sometimes with many columns,
one of our requirements is to be able to change the description and background color of the labelpresenter, to "highlight" important columns,
this is done by the user and saved in his settings.

The way we have achieved this seems to work fine, but it will only work properly if we don't use CellContainerGenerationMode="Recycle",
otherwise the headers will repeat on horizontal scrolling.

Our question is, is there a way to make this work with CellContainerGenerationMode="Recycle"? Using LazyLoad or Preload does have a noticeable performance
impact and we would prefer the faster "Recycle" mode, while still having this feature.

I have attached a sample project with two colored columns to better explain what we need, CellContainerGenerationMode is on LazyLoad now,
if you switch to recycle and start scrolling, our issue will be visible.

XamDataGridRecycle.zip

  • 30490
    Verified Answer
    Offline posted

    Hello Michael,

    I have been investigating into the sample project you have provided, and I have some information regarding the issue you are seeing.

    First, I will say that the way you are approaching this makes the behavior you are seeing where the headers are repeating expected. This is because when you set the CellContainerGenerationMode to “Recycle” the LabelPresenter elements are reused and recycled. Since your custom CustomizableGrid has its Background hard-coded from its Initialized event, this is recycled to other headers as well.

    To fix this, I have changed your sample a bit such that it relies on the TemplateBinding of the Background setter of the LabelPresenter Style and I have given it an x:Key to be used with the XamDataGrid.FieldSettings.LabelPresenterStyle property. The Initialize event of the CustomizableGrid has been removed. Instead, I have put together a Behavior using the Micorsoft.Xaml.Behaviors.Wpf NuGet package that handles the FieldLayoutInitialized event of the XamDataGrid and a “Style factory” method that programmatically generates a style based on yours that adds a new setter for the Background and applies the Style to the XamDataGrid Field’s Settings.LabelPresenterStyle property.

    I am attaching the modified version of the sample project here. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    8244.XamDataGridRecycle.zip