private static void HideDefinitionAndCacheLength(this DefinitionBase definition, WeakKeyDictionary <DefinitionBase, GridLength> gridLengthsCache) { var currentLength = definition.GetLength(); switch (currentLength.GridUnitType) { case GridUnitType.Auto: case GridUnitType.Star: // If the current unit is Auto or Star, we don't need to update the current or cached value. break; case GridUnitType.Pixel: // If current unit is Pixel, we need to set length to zero to hide the definition and update the cached value. gridLengthsCache[definition] = currentLength; definition.SetLength(new GridLength(0)); break; } }