question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ContentView inherits from the wrong base Layout class

See original GitHub issue

Description

There are two parallel layout implementations in .NET MAUI:

  1. The new layout implementation with the base class of Microsoft.Maui.Controls.Layout
  2. The legacy layout implementation from Xamarin.Forms with the base class of Microsoft.Maui.Controls.Compatibility.Layout

The new layout implementation is compatible with the new MAUI handlers. The old layout implementation from Xamarin.Forms is not compatible with the handlers and should be avoided.

The problem with the ContentView is that it has a handler, but is still inherits from the legacy layout Microsoft.Maui.Controls.Compatibility.Layout. This is a major source of bugs, as the usual layout logic might not be executed correctly or might not get executed at all on some platforms.

Steps to Reproduce

Download and run the attached sample project on Windows.

TestApp.zip

The sample project contains a single CustomView inheriting from ContentView. The sole purpose of that CustomView is to override all the virtual Measure, Arrange, Layout etc. methods of the base class and dump some debug output when they are called. The sample applications has two additional buttons to call the InvalidateMeasure method on the CustomView from the base VisualElement class and from the IView interface.

Observe the debug output of the application. You can also put breakpoints in the overridden methods to be sure. Notice that nothing happens: nothing is called at all. All the layout logic of the CustomView is completely discarded.

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

N/A

Did you find any workaround?

Unless Microsoft changes the implementation of the ContentView to inherit from the new Microsoft.Maui.Controls.Layut and implements the necessary glue code, I cannot suggest any viable workaround, except not using ContentView or any templated controls in the .NET MAUI applications.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
msftbot[bot]commented, Aug 30, 2022

We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

2reactions
drasticactionscommented, May 30, 2022

Wouldn’t this be an issue with the Telerik controls you’re using? I’m not sure how this is a MAUI issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MAUI ContentView can't inherit from custom base class
I have a ContentView called HomePageOrientationViewLoader that I want to use in a ContentPage called HomePage. HomePageOrientationViewLoader ...
Read more >
ContentView Class (Microsoft.Maui.Controls)
Gets or sets the LayoutOptions that define how the element gets laid in a layout cycle. This is a bindable property. (Inherited from...
Read more >
Layout Class (Xamarin.Forms)
Gets or sets a value that indicates whether this element is included in tab navigation. This is a bindable property. (Inherited from VisualElement)....
Read more >
Is there possible to support inheriting from a generic type ...
Recently, I tried to write a generic class to extend UIViewController and its all subclasses, so I wrote some codes like this:
Read more >
Using content views — iOS App Dev Tutorials
Create a new class named TextFieldContentView that inherits from UIView .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found