GridViewColumn.IsFrozen is not correctly updated when generating columns while the control is not visible

1 Answer 80 Views
GridView
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Eldoir asked on 20 Oct 2022, 01:14 PM | edited on 20 Oct 2022, 01:31 PM

Hello,

I'm generating columns dynamically, I have a RadGridView with LeftFrozenColumnCount = 1.
It is possible that my grid becomes not visible (for exemple, when switching tab in a TabControl).

But the columns my grid is bound to can still be re-generated.
It seems that way, the grid doesn't update the IsFrozen property of the columns.

I assume this is because the CoerceValueCallback for this propery checks for null on each column.DataControl and if so, returns the base value for the property, which in my case is always equal to false, because I've just generated the columns and they didn't get to the view yet.

I rely on this IsFrozen property to do some custom filtering logic, and it doesn't execute properly because the IsFrozen property isn't updated reliably.

I don't have any issue when coming back to the grid, because the IsFrozen property is then updated correctly: the real problem is in that this property isn't updated properly if the grid is not visible and we change the columns it's bound to.

What can I do to work around this?

Thanks! :)

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 24 Oct 2022, 07:22 PM

Hi Eldoir,

Generally, controls rarely has logic to trigger when the Visibility of element is triggered. WPF framework might exclude some elements from the measure/arrange process when visibility is collapsed. However, switching tabs in RadTabControl makes more significant effect - control might be unloaded from visual tree, this way disconnecting any bindings which are inherited from visual parents. Here are some initial tips you can try and if they do not work, could you please share some code from your setup, this will be easier for us to replicate the scenario on our side:
  
   - if you bind the IsFrozen to some property from ViewModel which is inherited - check if this ViewModel is lost when unloading the control -if yes, you can try to set the DataContext in code instead of relyon on viewmodel inheritance
   - if you are using RadTabControl, it provides a feature to preserve the content of the tabs when switching them. Please check out the following article:
RadTabControl how to keep the Content state
T
his might prevent the ViewModel from disconnecting and preserve the eventual IsFrozen Binding

Regards,
Petar Mladenov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
commented on 25 Oct 2022, 04:02 PM

Hi Petar,

I can't set the DataContext in code for design reasons on this project. And the ViewModel isn't lost when unloading the control, anyway!

I'm not using a RadTabControl either.

As a workaround, I subclassed GridViewDataColumn and added some custom fields to my columns when I create them dynamically, so that I can rely on those fields when performing my checks while the grid control is not loaded.

Thanks for your reply still!

Arthur

Petar Mladenov
Telerik team
commented on 26 Oct 2022, 01:20 PM

Hi Arthur,
Glad you have found a solution.
Please excuse me for missing to address the question regarding the value callback of the IsFrozen. You are correct, with the smaal difference, the logic you have guesses is in the CoerceValueCallback function:
        /// <summary>
        /// Coercion call back for IsFrozenProperty. Ensures that IsFrozen is set as per the 
        /// Grid's FrozenColumnCount property.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="baseValue"></param>
        /// <returns></returns>
        private static object OnCoerceIsFrozen(DependencyObject d, object baseValue)
        {
            GridViewColumn column = (GridViewColumn)d;
            GridViewDataControl dataGrid = column.DataControl;
            if (dataGrid != null)
            {
                return column.DisplayIndex < dataGrid.LeftFrozenColumnCountCache || column.DisplayIndex > dataGrid.InternalColumns.Count - 1 - dataGrid.RightFrozenColumnCountCache;
            }

            return baseValue;
        }
Tags
GridView
Asked by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Petar Mladenov
Telerik team
Share this question
or