Hey,
I've bumped into a problem where sometimes on ALT+TAB data from a grid disappears as you can see on attached photo.
We managed to fix it with the code below but it requires manual screen "flashing" namely hidding and showing any of the grid's column. The view that contains the grid is once created when navigated to then saved to cache. On next navigation it is grabbed from the cache. We don't create views on every navigation.
As you can see only things that are labels disappeard.
Window? _window;
public AccountsClientsView(AccountsClientsViewModel accountsClientsViewModel, IPreferencesService preferencesService)
{
_viewModel = accountsClientsViewModel;
await Task.Yield();
BuildContent();
_viewModel.IsLoadingContent = false;
SubscribeToWindowActivation();
Unloaded += OnUnloaded;
}
void OnUnloaded(object? sender, EventArgs e)
{
Unloaded -= OnUnloaded;
UnsubscribeFromWindowActivation();
}
void SubscribeToWindowActivation()
{
_window = Window;
if (_window is not null)
_window.Activated += OnWindowActivated;
}
void UnsubscribeFromWindowActivation()
{
if (_window is null)
return;
_window.Activated -= OnWindowActivated;
_window = null;
}
// Telerik RadDataGrid on Windows stops painting its realized rows after the
// window is deactivated and reactivated (e.g. Alt+Tab); the data reappears
// only once the user scrolls. Reactivating revives each grid the same way a
// manual scroll would, keeping the current scroll position and selection.
void OnWindowActivated(object? sender, EventArgs e)
{
Dispatcher.Dispatch(() =>
{
foreach (var (grid, _) in _viewModel.Grids)
RefreshGridPreservingScroll(grid);
});
}
void RefreshGridPreservingScroll(RadDataGrid grid)
{
#if WINDOWS
// Nudge the internal ScrollViewer by 1px and back: this triggers the
// same re-virtualization a manual scroll does, so the rows repaint
// while the original vertical position is restored.
if (grid.Handler?.PlatformView is not Microsoft.UI.Xaml.FrameworkElement platformView)
return;
var scrollViewer = FindNativeScrollViewer(platformView);
if (scrollViewer is null)
return;
var offset = scrollViewer.VerticalOffset;
var nudged = offset > 1 ? offset - 1 : offset + 1;
scrollViewer.ChangeView(null, nudged, null, true);
grid.Dispatcher.DispatchDelayed(
TimeSpan.FromMilliseconds(30),
() => scrollViewer.ChangeView(null, offset, null, true));
#else
if (grid.Columns.Count == 0)
return;
var firstColumn = grid.Columns[0];
var isVisible = firstColumn.IsVisible;
firstColumn.IsVisible = !isVisible;
firstColumn.IsVisible = isVisible;
#endif
}
#if WINDOWS
static Microsoft.UI.Xaml.Controls.ScrollViewer? FindNativeScrollViewer(Microsoft.UI.Xaml.DependencyObject root)
{
var childCount = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(root);
for (var i = 0; i < childCount; i++)
{
var child = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetChild(root, i);
if (child is Microsoft.UI.Xaml.Controls.ScrollViewer scrollViewer)
return scrollViewer;
var descendant = FindNativeScrollViewer(child);
if (descendant is not null)
return descendant;
}
return null;
}
#endif
Hi Wojtek,
We are not aware of such issue with RadDataGrid. Could you please provide more details about your project setup and the steps required to reproduce the problem?
I'm looking forward to hearing from you.
Regards,
Kalin
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.
Hi Wojtek,
I have created a sample app using the described scenario and cannot reproduce any issues when alt+tab is used. For sure I am missing something from the setup. As my colleague Kalin shared we will need the project setup and steps to reproduce. If it is an option, you can also attach a sample test app in which the behavior happens.