Platform-specific XAML in .NET MAUI
Introduction
Cross-platform development is amazing, you only need to write the code once and then you can deploy to multiple platforms all from the same code base. Or so the theory goes. In reality, each platform has specific, native capabilities and...
blog.ewers-peters.de5 min read
Actually, the View control can't be used as a base class for the return type (I'm not sure why), but we have to use another View-derived control like a Grid or any layout. Also, the above use of the <OnIdiom> markup is invalid. This markup does not use the <On> tag, nor Idiom attribute like what <OnPlatform> does. It should be like:
<OnIdiom x:TypeArguments="Grid"> <OnIdiom.Desktop> <views:DesktopView /> </OnIdiom.Desktop> <OnIdiom.Phone> <views:MobileView /> </OnIdiom.Phone> </OnIdiom> May I ask Microsoft, where is constancy? You can also use these markups in a short-handed way:
<Grid BackgroundColor="{OnIdiom Desktop=AliceBlue, Phone=Aqua}"/> Thanks for the great work! Hashnode first experience to create an account is a matter of time-waste though.