[Solved] DataGrid's data disappear from grid after ALT+TAB

0 Answers 63 Views
DataGrid
Wojtek
Top achievements
Rank 1
Iron
Wojtek asked on 03 Sep 2026, 09:11 AM | edited on 03 Sep 2026, 09:12 AM

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


Kalin
Telerik team
commented on 04 Sep 2026, 12:17 PM

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.

Didi
Telerik team
commented on 09 Sep 2026, 06:09 AM

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. 

Wojtek
Top achievements
Rank 1
Iron
commented on 28 Sep 2026, 08:38 AM

Hey,

I'm attaching project with reproduced issue however, this is not everytime scenario. It happens rarelly so please play with it until issue happens.
Wojtek
Top achievements
Rank 1
Iron
commented on 28 Sep 2026, 08:39 AM | edited

Hey, i attached sample project in the anwser. Please have a look at it.
Didi
Telerik team
commented on 30 Sep 2026, 08:31 AM

Hi Wojtek,

Thank you for the project.

I tried many times still no issues. I have also replaced the template column with the built-in columns and removed the CellTemplates still no issues.

I have attached the code of the MainPage.xaml.cs file. The DataGrid uses the built-in columns without cell templates. Please test on your side and let me know whether the behavior appears with it. Send images.

 

No answers yet. Maybe you can help?

Tags
DataGrid
Asked by
Wojtek
Top achievements
Rank 1
Iron
Share this question
or