From 507100ac2f63f94f2de2e0c97d6b2a09da64f117 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:35:24 +0000 Subject: [PATCH 1/2] Initial plan From ea28a1a72d7a068be4331ae573df6890d8bae259 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:42:50 +0000 Subject: [PATCH 2/2] Add comprehensive device-independent units documentation Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> --- docs/TOC.yml | 2 + docs/fundamentals/gestures/swipe.md | 2 +- docs/fundamentals/triggers.md | 3 + docs/user-interface/align-position.md | 2 +- .../device-independent-units.md | 211 ++++++++++++++++++ docs/user-interface/fonts.md | 4 +- .../includes/basic-animation-dotnet10.md | 2 +- 7 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 docs/user-interface/device-independent-units.md diff --git a/docs/TOC.yml b/docs/TOC.yml index ff010a511..157a2ad0c 100644 --- a/docs/TOC.yml +++ b/docs/TOC.yml @@ -277,6 +277,8 @@ href: user-interface/controls/index.md - name: Align and position controls href: user-interface/align-position.md + - name: Device-independent units + href: user-interface/device-independent-units.md - name: Handlers items: - name: Overview diff --git a/docs/fundamentals/gestures/swipe.md b/docs/fundamentals/gestures/swipe.md index 30a99ce7e..da8516ba1 100644 --- a/docs/fundamentals/gestures/swipe.md +++ b/docs/fundamentals/gestures/swipe.md @@ -13,7 +13,7 @@ In .NET MAUI, drag gesture recognition is provided by the , of type , which is executed when a swipe gesture is recognized. - , of type `object`, which is the parameter that's passed to the `Command`. - , of type , which defines the direction -- , of type `uint`, which represents the minimum swipe distance that must be achieved for a swipe to be recognized, in device-independent units. The default value of this property is 100, which means that any swipes that are less than 100 device-independent units will be ignored. +- , of type `uint`, which represents the minimum swipe distance that must be achieved for a swipe to be recognized, in device-independent units. The default value of this property is 100, which means that any swipes that are less than 100 device-independent units will be ignored. For more information about device-independent units, see [Device-independent units](../../user-interface/device-independent-units.md). These properties are backed by objects, which means that they can be targets of data bindings, and styled. diff --git a/docs/fundamentals/triggers.md b/docs/fundamentals/triggers.md index e9ffaa0a1..ad2595c0a 100644 --- a/docs/fundamentals/triggers.md +++ b/docs/fundamentals/triggers.md @@ -370,6 +370,9 @@ The and indicates that the corresponding will be applied when the current window width is >= 800 device-independent units and the current window height is >= 1200 device-independent units. +> [!NOTE] +> For more information about device-independent units, see [Device-independent units](../user-interface/device-independent-units.md). + ### Compare state trigger The triggers a change when a property is equal to a specific value. This trigger has two bindable properties: diff --git a/docs/user-interface/align-position.md b/docs/user-interface/align-position.md index 59285c117..6bf384e50 100644 --- a/docs/user-interface/align-position.md +++ b/docs/user-interface/align-position.md @@ -59,7 +59,7 @@ The following diagram illustrates the two concepts: :::image type="content" source="media/align-position/margin-padding.png" alt-text="Margin and padding concepts." border="false"::: > [!NOTE] -> `Margin` values are additive. Therefore, if two adjacent elements specify a margin of 20 device-independent units, the distance between the elements will be 40 device-independent units. In addition, margin and padding values are additive when both are applied, in that the distance between an element and any content will be the margin plus padding. +> `Margin` values are additive. Therefore, if two adjacent elements specify a margin of 20 device-independent units, the distance between the elements will be 40 device-independent units. In addition, margin and padding values are additive when both are applied, in that the distance between an element and any content will be the margin plus padding. For more information about device-independent units, see [Device-independent units](device-independent-units.md). The `Margin` and `Padding` properties are both of type `Thickness`. There are three possibilities when creating a `Thickness` structure: diff --git a/docs/user-interface/device-independent-units.md b/docs/user-interface/device-independent-units.md new file mode 100644 index 000000000..871982d09 --- /dev/null +++ b/docs/user-interface/device-independent-units.md @@ -0,0 +1,211 @@ +--- +title: "Device-independent units" +description: "Learn about device-independent units in .NET MAUI and how they relate to platform-specific unit systems like iOS points and Android density-independent pixels." +ms.date: 12/19/2024 +--- + +# Device-independent units + +.NET Multi-platform App UI (.NET MAUI) uses **device-independent units** as its universal measurement system across all platforms. This unit system provides a consistent way to specify sizes, positions, margins, padding, and other measurements that automatically adapt to different screen densities and device types. + +## What are device-independent units? + +Device-independent units (DIUs) are a virtual unit of measurement that represents a consistent physical size across different devices and platforms, regardless of screen density or resolution. One device-independent unit is designed to represent approximately 1/160th of an inch (0.15875 mm) of physical screen space. + +The key characteristics of device-independent units include: + +- **Platform consistency**: The same value produces visually similar results across iOS, Android, Windows, and macOS +- **Density independence**: Automatically scales based on screen density to maintain physical size +- **Developer simplicity**: Use a single unit system instead of platform-specific calculations + +## Relationship to platform-specific units + +Device-independent units in .NET MAUI correspond directly to the native unit systems used by each platform: + +### iOS - Points + +On iOS, device-independent units map to **points** (pt): +- 1 device-independent unit = 1 iOS point +- Points automatically scale based on device pixel density +- iPhone standard density: 1 point = 1 pixel +- iPhone Retina displays: 1 point = 2-4 pixels (depending on the device) + +### Android - Density-independent pixels + +On Android, device-independent units map to **density-independent pixels** (dp or dip): +- 1 device-independent unit = 1 Android dp +- Based on 160 DPI as the baseline density +- Automatically scales: `pixels = dp × (dpi / 160)` +- Common scale factors: 1x (mdpi), 1.5x (hdpi), 2x (xhdpi), 3x (xxhdpi), 4x (xxxhdpi) + +### Windows - Device-independent pixels + +On Windows, device-independent units map to **device-independent pixels**: +- 1 device-independent unit = 1 Windows device-independent pixel +- Based on 96 DPI as the baseline +- Scales with system DPI settings and display scale factor + +### macOS - Points + +On macOS, device-independent units map to **points**: +- 1 device-independent unit = 1 macOS point +- Similar to iOS, points scale based on display density +- Standard displays: 1 point = 1 pixel +- Retina displays: 1 point = 2 pixels + +## Usage in .NET MAUI + +Device-independent units are used throughout .NET MAUI for various measurements: + +### Layout and positioning + +```xaml + +