Chuyển đến nội dung
Skillpedia
Ứng dụng di động5.8k · #14587

maui-safe-area

Skill này làm gì

Skill này hướng dẫn bố cục vùng an toàn và tràn viền trong ứng dụng .NET MAUI dành cho .NET 10 trở lên. Skill dành cho lập trình viên có nội dung chồng lên thanh hệ thống hoặc bàn phím trên điện thoại và máy tính bảng.

Khi nào nên dùng

  • ✓Khi nội dung bị chồng lên thanh trạng thái, tai thỏ hoặc thanh chỉ báo nhà sau một bản cập nhật.
  • ✓Khi bạn muốn có màn hình tràn viền như trình xem ảnh hoặc bản đồ.
  • ✓Khi một màn hình chat hoặc biểu mẫu cần tránh bàn phím.

Liên kết skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-safe-area/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-safe-area/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Màn hình chat MAUI của tôi bị bàn phím che trên Android. Sửa bố cục để ô nhập luôn hiển thị.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra phiên bản mục tiêu của dự án, rồi dùng các thiết lập vùng an toàn mới cho từng cạnh hoặc thiết lập nền tảng cũ hơn cho các phiên bản trước.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Safe Area & Edge-to-Edge Layout (.NET 10+)

.NET 10 introduces a brand-new, cross-platform safe area API that replaces the legacy iOS-only UseSafeArea and the layout-level IgnoreSafeArea properties. The new SafeAreaEdges property and SafeAreaRegions flags enum give you per-edge, per-control safe area management on Android, iOS, and Mac Catalyst from a single API surface.

This is new API surface in .NET 10. If the project targets .NET 9 or earlier, these APIs do not exist. Guide the developer to the legacy ios:Page.UseSafeArea and Layout.IgnoreSafeArea properties instead.

When to Use

  • Content overlaps status bar, notch, Dynamic Island, or home indicator after upgrading to .NET 10
  • Implementing edge-to-edge / immersive layouts (photo viewers, video players, maps)
  • Keyboard avoidance for chat or form UIs
  • Migrating from ios:Page.UseSafeArea, Layout.IgnoreSafeArea, or WindowSoftInputModeAdjust.Resize
  • Blazor Hybrid apps that need CSS env(safe-area-inset-*) coordination
  • Mixed layouts with an edge-to-edge header but a safe-area-respecting body

When Not to Use

  • Projects targeting .NET 9 or earlier — use the legacy iOS-specific APIs
  • General page layout questions unrelated to system bars or keyboard — use standard layout guidance
  • App lifecycle or navigation structure — use maui-app-lifecycle or Shell guidance
  • Theming or visual styling — use the maui-theming skill

Inputs

  • Target framework: must be net10.0-* or later for the new APIs
  • Target platforms: Android, iOS, Mac Catalyst (Windows does not have system bar insets)
  • UI approach: XAML/C#, Blazor Hybrid, or MauiReactor

SafeAreaRegions Enum

[Flags]
public enum SafeAreaRegions
{
    None      = 0,       // Edge-to-edge — no safe area padding
    SoftInput = 1 << 0,  // Pad to avoid the on-screen keyboard
    Container = 1 << 1,  // Stay inside status bar, notch, home indicator
    Default   = -1,      // Use the platform default for the control type
    All       = 1 << 15  // Respect all safe area insets (most restrictive)
}

SoftInput and Container are combinable flags: SafeAreaRegions.Container | SafeAreaRegions.SoftInput = respect system bars and keyboard.

SafeAreaEdges Struct

public readonly struct SafeAreaEdges
{
    public SafeAreaRegions Left { get; }
    public SafeAreaRegions Top { get; }
    public SafeAreaRegions Right { get; }
    public SafeAreaRegions Bottom { get; }

    // Uniform — same value for all four edges
    public SafeAreaEdges(SafeAreaRegions uniformValue)

    // Horizontal / Vertical
    public SafeAreaEdges(SafeAreaRegions horizontal, SafeAreaRegions vertical)

    // Per-edge
    public SafeAreaEdges(SafeAreaRegions left, SafeAreaRegions top,
                         SafeAreaRegions right, SafeAreaRegions bottom)
}

Static presets: SafeAreaEdges.None, SafeAreaEdges.All, SafeAreaEdges.Default.

XAML Type Converter

Follows Thickness-like comma-separated syntax:

<!-- Uniform -->
SafeAreaEdges="Container"

<!-- Horizontal, Vertical -->
SafeAreaEdges="Container, SoftInput"

<!-- Left, Top, Right, Bottom -->
SafeAreaEdges="Container, Container, Container, SoftInput"

Control Defaults

Control Default Notes
ContentPage None Edge-to-edge. Breaking change from .NET 9 on Android.
Layout (Grid, StackLayout, etc.) Container Respects bars/notch, flows under keyboard
ScrollView Default iOS maps to automatic content insets. Only Container and None take effect.
ContentView None Inherits parent behavior
Border None Inherits parent behavior

Breaking Changes from .NET 9

ContentPage default changed to None

In .NET 9, Android ContentPage behaved like Container. In .NET 10, the default is None on all platforms. If your Android content goes behind the status bar after upgrading:

<!-- .NET 10 default — content extends under status bar -->
<ContentPage>

<!-- Restore .NET 9 Android behavior -->
<ContentPage SafeAreaEdges="Container">

WindowSoftInputModeAdjust.Resize superseded

WindowSoftInputModeAdjust.Resize still exists and still compiles (it is not removed and not obsolete), but it is Android-only. For cross-platform keyboard avoidance prefer SafeAreaEdges="All" (or the SoftInput region) on the ContentPage.

Usage Patterns

Edge-to-edge immersive content

Set None o

Câu hỏi thường gặp

Skill có hoạt động trên .NET 9 không?

Không dùng được thiết lập mới. Với .NET 9 trở xuống, các thiết lập riêng cho nền tảng cũ hơn được dùng.

Skill có bao quát việc tránh bàn phím không?

Có. Tránh bàn phím là một trong các trường hợp được bao quát.

Skill có bao quát ứng dụng Blazor Hybrid không?

Có. Skill bao quát các giá trị CSS vùng an toàn cho Blazor Hybrid.

Chi tiết

Mô tả gốc của tác giả

.NET MAUI safe area and edge-to-edge layout guidance for .NET 10+. Covers the new SafeAreaEdges property, SafeAreaRegions enum, per-edge control, keyboard avoidance, Blazor Hybrid CSS safe areas, migration from legacy iOS-only APIs, and platform-specific behavior for Android, iOS, and Mac Catalyst. USE FOR: "safe area", "edge-to-edge", "SafeAreaEdges", "SafeAreaRegions", "keyboard avoidance", "notch insets", "status bar overlap", "iOS safe area", "Android edge-to-edge", "content behind status bar", "UseSafeArea migration", "soft input keyboard", "IgnoreSafeArea replacement". DO NOT USE FOR: ge

repo: dotnet/skills

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14587
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự