RadDataGrid disappeared when switching views

1 Answer 33 Views
DataGrid
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 16 May 2022, 05:19 AM | edited on 16 May 2022, 05:19 AM

Hi,

When I switch between views in my app the grid not seen I see only label(See attached screenshhot).

I added sample code like in my app without data.

What can be the problem?

Thanks,,

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 16 May 2022, 06:13 AM

More info: When loading first time I see data in one view, later I navigate to other view I see only label.

When I maximized the window I see the data.

 

Lance | Manager Technical Support
Telerik team
commented on 16 May 2022, 07:56 PM

I see the code is still using a VerticalStackLayout and StackLayout. Although I see you're using an explicit HeightRequest to prevent the effects of the StackLayout, I'm still suspicious of it because the symptoms you're explaining are what happens when the measure & arrange pass is not working due to size contraints

Please switch to a Grid and put UI virtualized controls like the DataGrid and RadListView only inside star-sized RowDefintions.

Here's what that would look like in the HistoryPage

Understanding DataGridBorderStyle is not a Style object

Finally, I see that you're sharing the same instance of DataGridBorderStyle with every column. DataGridBorderStyle is not a Style... it is an object instance of type DataGridBorderStyle

Why does this matter? In XAML, a Style is essentially a "definition" of what values to use in the target object, it is not an instance of that end object. Whereas a DataGridBorderStyle is an instance of a DataGridBorderStyle object and is not a template that can be reused.

So, please change your DataGrid so that every column has it's own, separate instance, of the DataGridBorderStyle object.

Here's a screenshot of what the updated code should look like, each column has its own instance of the item:

 

Or, if you prefer not to use StaticResources, you can nest it inside the columns

 

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 16 May 2022, 09:21 PM

Hi Daniel,

I've attached your test project, with the fixes to the problems I mentioned in my earlier comment. at runtime, things appear to be working as expected.

Here are some screenshots when I run the project.

1. At launch:

2. Clicking Button 1:

3. Clicking Button 2:

Further Investigation

However, as you mentioned there is no sample data, so I cannot test that side of things. Please take my demo, read my notes and comments and apply these changes to your app.

If you still have an issue, please update my demo again, but with the actual data model you use and sample data that faithfully represents the real data. Ultimately, I need to be able to give the developers a project that shows the problem at runtime.

Important Note About UI Virtualization

I see you have other implementations in other forum threads where your code has a RadListView or a DataGrid inside a VerticalStackLayout. The same problem can affect you there.

My advice is to never use a StackLayout unless you are explicitly intending to "squish" the children to the bare minimum space and not allow forced measurement recalculation by the child. Always use a Grid or other layout parent that allows the child to expand into available space.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 May 2022, 07:49 AM | edited

I attached demo that replicated the issue,

Press on button 1 coupled of times =? data are blank=> do not maximize the window.

 

Lance | Manager Technical Support
Telerik team
commented on 17 May 2022, 03:02 PM

Hi Daniel,

Thank you for the updated project. I was able to see the issue at runtime. I have further simplified the project to the bare minimum needed to reproduce the problem and created a bug report => DataGrid Won't Render 2nd Instance (telerik.com)

Unfortunately, I do not have a workaround for you. I attempted to invalidate the layout with InvalidateLayout, which forces a UI element to redraw itself, but even that didn't work.

My only suggestion would be to use normal navigation instead of trying to invent your own with Grid.Children(). this way you can use normal ContentPage objects and rely on the well structured Shell navigation methods. See .NET MAUI Shell navigation - .NET MAUI | Microsoft Docs.

 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 May 2022, 04:01 PM

Can you please edit the demo to use shell like in this structure ?
Lance | Manager Technical Support
Telerik team
commented on 17 May 2022, 04:08 PM

If I did the work for you on this one project, you still wouldn't understand how Shell works. You can see how to use Shell here Create a .NET MAUI Shell app - .NET MAUI | Microsoft Docs.(continue through all the tutorials)

In your ShellPage is where you'll have the different content pages, like DashboardPage and HistoryPage. The shell mechanism will create the tabs or flyout page for you. 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 May 2022, 04:43 PM

I will update tomorrow this project with shell.
Lance | Manager Technical Support
Telerik team
commented on 17 May 2022, 04:47 PM

I have a little bit of good news. I just looked through the developer's work items and found that they are already aware of the problem. The bad news is there is not currently a date where it expected to be fixed. However, it does have a higher priority that most items. 

You will know when we have a released a fix for it when the official bug report gets changed to Fixedhttps://feedback.telerik.com/maui/1565483-datagrid-won-t-render-2nd-instance 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 May 2022, 04:54 PM

There is  another issue with rendering grid i will build demo with shell and let you know.
Lance | Manager Technical Support
Telerik team
commented on 17 May 2022, 05:00 PM

We are currently aware of problems with the following items on WinUI

  • - Rendering TemplateColumn cell content (will not appear until resize/hover)
  • - Rendering of any CellEditTemplate
  • - Rendering of any CellContentTemplate

If your experience has those, there's no need for a new bug report, they're covered by the same  fundamental rendering issue in the existing bug report.

 

 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 18 May 2022, 04:30 AM

I would like to ask you.

I have login and from there I want to move to appshell.


 public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new LoginPage();//new AppShell();
        }
    }
In login I have login button and from there i want to move to new app shell, how is done ? in code?
Lance | Manager Technical Support
Telerik team
commented on 18 May 2022, 01:44 PM

That is a question better asked in the Microsoft forums because they're the one who built Shell, but I can give you my thoughts....

AppShell is not a "page" that you navigate to, it is the entire root of the application that handles the side drawer and page navigation for you. In your shell page's XAML, you could have the LoginPage, MainPage and DetailsPage, etc.

When the app loads, you can navigate to LoginPage first if the user needs to login, but if the user already has an authentication token stored, you can instead navigate to the MainPage.

Here's a pseudo example:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        // Only use AppShell as the root of the application
        MainPage = new AppShell();
    }
}

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:views="clr-namespace:MyApp.Views"
       x:Class="MyApp.AppShell">
    <FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
        <ShellContent Title="Login"
                      Icon="login.png"
                      ContentTemplate="{DataTemplate views:LoginPage}" />
        <ShellContent Title="Home"
                      Icon="home.png"
                      ContentTemplate="{DataTemplate views:HomePage}" />
        <ShellContent Title="Details"
                      Icon="details.png"
                      ContentTemplate="{DataTemplate views:DetailsPage}" />
    </FlyoutItem>
</Shell>

if(UserIsLoggedIn)
{
    await Shell.Current.GoToAsync("/main");
}
else
{
    await Shell.Current.GoToAsync("/login");
}

Further Help With Shell

I urge you to take a closer look at all the many resources for Shell online. You can also use the Xamarin.Forms shell examples because the code is the same for MAUI.

The Shell Navigation documentation's tutorial will show you how to layout your pages and how to navigate between them => .NET MAUI Shell navigation - .NET MAUI | Microsoft Docs

To ask specific questions about Shell, you can use the Xamarin.Forms forums (Microsoft hasn't setup forums for MAUI yet) => dotnet-xamarinforms - Microsoft Q&A.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 18 May 2022, 02:36 PM | edited

I'm  looking  on videoes.

Where you put this code I want login will be alone.

if(UserIsLoggedIn) { await Shell.Current.GoToAsync("/main"); } else { await Shell.Current.GoToAsync("/login"); }

 


Lance | Manager Technical Support
Telerik team
commented on 18 May 2022, 03:19 PM

That depends on your app's lifecycle. I can't tell you where to use your custom business logic or how to store the user token and when to check it after the app loads. You'd probably want to do it in the AppShell when it loads (because that's when you need to make a decision on what page to navigate to).

Please follow the entire tutorial on how to use Shell. Do not just read it and try to plug in the code into your existing app at the same time because you'll be dividing your attention. If you follow the tutorial until completion, then you can go ahead and try it in your real app because you'll have already understood the fundamentals.

Lance | Manager Technical Support
Telerik team
commented on 18 May 2022, 04:25 PM

I have great news! Microsoft just released it's first new course on .NET MAUI Build mobile and desktop apps with .NET MAUI - Learn | Microsoft Docs.

That is actually a full Learning Path that covers a wide range in topics and is a full 5 hours and 45 minutes! You can go from module to module to learn all the different aspects of .NET MAUI.

There you can learn all the different topics you've been looking for help with. This is a good sign that the MAUI documentation is getting ready for the first release of .NET MAUI.

Lance | Manager Technical Support
Telerik team
commented on 21 May 2022, 01:21 AM

Quick Update. I have spent all day working on trying to workaround this using a ContentPage to ContentPage navigation scenario, but was ultimately unsuccessful.

I can only say that we will need to wait for the UI for MAUI developers to identify the cause. You will receive a notification from the MAUI team in the open Bug Report, there's nothing more we can discuss in this thread.

Here's some screenshots, that DataGrid will have trouble rendering when you come back from the details page.

Routes Page (DataGrid works on the first load)