C#
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Object-Oriented C#
-
Section 4: Working with Data
-
Section 5: Error Handling
-
Section 6: Delegates and Events
-
Section 7: Async Programming
-
Section 8: More Language Features
-
Section 9: File I/O and Serialization
-
Section 10: Networking in .NET
-
Section 11: The .NET Ecosystem
-
Section 12: Memory and Performance
-
Section 13: Concurrency Beyond Async
-
Section 14: Reflection and Attributes
-
Section 15: Testing and Best Practices
-
Section 16: Design Patterns in C#
-
Section 17: Standard Library Deep Dive
-
Section 18: Data Structures and Algorithms in C#
-
Section 19: GUI and Desktop Development Overview
-
Section 20: Practical Projects
-
Section 21: More Practice Exercises
-
Section 22: More Standard Library and Text Processing
-
Section 23: More Design Patterns
-
Section 24: More Projects
-
Section 25: Interview Practice
-
Section 26: C# Keywords Reference (Modifiers)
-
Section 27: C# Keywords Reference (Statements)
-
Section 28: C# Keywords Reference (Operators)
-
Section 29: BCL: System.Collections.Generic
-
Section 30: BCL: System.Linq
-
Section 31: BCL: System.Threading
-
Section 32: BCL: System.IO
-
Section 33: BCL: System.Text and System.Text.Json
-
Section 34: BCL: System.Net.Http
-
Section 35: C# Language Specification Topics
-
Section 36: More Practice Exercises
-
Section 37: More Async Patterns
-
Section 38: More BCL: System.Reflection and System.Diagnostics
-
Section 39: Nullable Reference Types In Depth
-
Section 40: C# Records and Pattern Matching In Depth
-
Section 41: Dependency Injection Deep Dive
-
Section 42: More Interview and Whiteboard Practice
127: An Overview of .NET MAUI for Cross-Platform Apps
Imagine you've designed a high-resolution vector logo for a client. You don't create a separate image for their business cards, another for their website, and another for a giant billboard. Instead, you create one "master" design. When it's time to publish, the printing software handles the specifics: it scales the logo for the card, optimizes the pixels for the web, and adjusts the resolution for the vinyl billboard. The intent is the same, but the implementation changes based on the medium.
That is exactly how .NET MAUI (Multi-platform App UI) works. You aren't writing four different apps for iOS, Android, Windows, and macOS. You're creating a "master design" in C# and XAML, and MAUI handles the translation to the native controls of each operating system.
One Blueprint, Four Different Foundations
In the old days, if you wanted a button on an iPhone and a button on an Android device, you had to use two different languages and two different sets of libraries. MAUI abstracts this. When you define a Button in MAUI, you aren't telling the computer to draw a generic rectangle; you're telling MAUI, "I need a button here."
- On iOS: MAUI tells the OS to render a
UIButton. - On Android: It renders an
android.widget.Button. - On Windows: It uses
WinUI 3.
I've spent years jumping between frameworks, and the beauty of MAUI is that it doesn't try to "mimic" the look of these platforms with custom drawings (which often feel "uncanny" or slightly off to the user). It uses the actual native components, so your app feels like it belongs on the device.
Designing the Look with XAML
While you can build your entire UI in C#, most of us use XAML (Extensible Application Markup Language). It's essentially XML that describes your layout. It keeps your "view" separate from your "logic," which saves you a massive headache when you need to change the UI without breaking the backend code.
Take a look at this snippet for a simple Project Timer interface. Notice how we use layouts like VerticalStackLayout to organize elements without worrying about the exact pixel coordinates of a specific screen:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ProjectTimer.MainPage">
<VerticalStackLayout Padding="30" Spacing="25">
<Label Text="Active Project: Website Redesign"
FontSize="24"
HorizontalOptions="Center" />
<Label x:Name="TimerLabel"
Text="00:00:00"
FontSize="48"
FontAttributes="Bold"
HorizontalOptions="Center" />
<Button Text="Start Timer"
Clicked="OnStartClicked"
BackgroundColor="DarkBlue"
TextColor="White" />
</VerticalStackLayout>
</ContentPage>
If you ran this on an iPad, the VerticalStackLayout would center everything across a wide screen. On a narrow Android phone, it would stack them tightly. You write the markup once; the framework handles the geometry.
The Handlers Under the Hood
You might be wondering: "If it's all abstracted, how do I do something that only exists on one platform?" Say you need to access a very specific iOS-only API for the camera or a Windows-specific registry key. This is where "Handlers" come in.
MAUI uses a handler architecture that maps the cross-platform control to the native one. I usually tell my students to think of Handlers as the "translators." If you ever find that the default translation isn't specific enough, you can write a "Platform-Specific" override. You can literally wrap code in #if ANDROID or #if IOS blocks within your C# files to execute code only on that specific OS. It gives you the speed of cross-platform development without the "glass ceiling" of limited functionality.
📋 Practical Task
Build a Platform-Aware Device Dashboard
Your goal is to create a single-page MAUI application that identifies which operating system is currently running and displays a custom message based on that platform.
Requirements:
- Create a
ContentPagewith aVerticalStackLayout. - Add a
Labelthat will display the platform name (e.g., "You are running this on Android"). - Add a
Buttonlabeled "Check System". - In the C# code-behind (the
.xaml.csfile), implement the button click event. Use theDeviceInfo.Current.Platformproperty from theMicrosoft.Maui.Devicesnamespace to determine the current OS. - Update the label's text based on the platform detected. For an extra challenge, change the
TextColorof the label to a different color depending on the OS (e.g., Green for Android, Blue for iOS, Red for Windows).
There are no comments for now.