Control Not Visible on Smaller Screens or High-Scale Displays in MAUI

Rohan Savnani 0 Reputation points
2025-03-15T17:54:12.1433333+00:00

I have a custom control in my .NET MAUI application that is not visible under the following conditions:

  • The screen size is less than 15.6 inches
  • The resolution is lower than 1920 x 1080
  • The display scale is greater than 125%

The control works perfectly on larger screens with high resolutions and default scaling. However, on smaller screens or high DPI settings, it either disappears or doesn't render properly.

Has anyone faced similar issues? How can I ensure the control remains visible and adapts properly to different screen sizes, resolutions, and scaling settings?

Developer technologies | .NET | .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 10,555 Reputation points Microsoft External Staff Moderator
    2025-08-18T03:25:57.75+00:00

    Hello,

    This probably happens when a control's size is fixed or when it doesn't correctly interpret the screen's density and scaling.

    Below, I outline the potential causes and their respective solutions to ensure your control renders correctly across various screen sizes and densities settings.

    Potential Causes and Solutions

    1. Fixed Dimensions in Control Sizing

    • Issue: Utilizing hardcoded values for WidthRequest and HeightRequest (e.g., 400x300 pixels) may cause the control to appear correctly on larger screens but become oversized or clipped on smaller displays, resulting in the layout system hiding the control.
    • Solution: Remove fixed size constraints to allow the control to adapt to its parent layout. Employ adaptive layout containers such as Grid with proportional sizing (e.g., RowDefinition or ColumnDefinition set to *) or FlexLayout to ensure dynamic resizing based on available space.
          <!-- Good Practice: Adaptive sizing with Grid -->
          <Grid RowDefinitions="*, 0.3*, *"
              ColumnDefinitions="*, 0.8*, *">
       
              <Frame Grid.Row="1"
                  Grid.Column="1"
                  BackgroundColor="LightGreen">
                  <Label Text="This is responsive and always fit."
                      HorizontalOptions="Center"
                      VerticalOptions="Center" />
              </Frame>
       
          </Grid>
      

    2. Screen Density Mismatch

    • Issue: .NET MAUI operates with device-independent units, and failure to account for screen density (especially on high-scale displays, e.g., 150%) can result in oversized rendering or clipping. This occurs when custom drawing logic or image handling assumes a 1:1 pixel-to-unit ratio.
    • Solution: Adjust calculations using the DeviceDisplay.MainDisplayInfo.Density property. For custom graphics or pixel-based operations, apply the formula: physicalPixels = mauiUnits * density to ensure accurate scaling across different display densities settings.

    3. Incorrect Layout Measurement Implementation

    • Issue: If your custom control subclasses View or Layout, an improper MeasureOverride implementation may return invalid size values (e.g., 0 or infinite size), causing the layout system to exclude the control from rendering.
    • Solution: Review and refine the MeasureOverride and ArrangeOverride methods to ensure they accurately compute the control’s desired size based on the constraints provided by the parent layout. Verify that the returned measurements align with the control’s content and layout requirements.

    4. Improper Use of StackLayout within ScrollView

    • Issue: Placing a StackLayout inside a ScrollView without constraining its height can lead to measurement issues, as ScrollView allows infinite vertical space, potentially causing rendering failures on smaller screens.
    • Solution: Ensure the content within the ScrollView has a defined size constraint. Alternatively, replace StackLayout with a layout container like Grid that inherently manages sizing more effectively.
          <!-- Good Practice: Use a Grid to constrain the content -->
          <ScrollView>
              <Grid RowDefinitions="Auto, Auto, Auto">
                  <Label Grid.Row="0" Text="Item" HeightRequest="50" />
                  <Label Grid.Row="1" Text="Item" HeightRequest="50" />
                  <Label Grid.Row="2" Text="Item" HeightRequest="50" />
              </Grid>
          </ScrollView>
       
          <!-- Best Practice for long lists: Use a CollectionView -->
          <CollectionView>
              <!-- ... items ... -->
          </CollectionView>
      

    I hope this helps clarify your issue.

    References

    You can refer to the following resources for more detailed guidance on handling layouts and screen density in .NET MAUI:

    1 person found this answer helpful.

  2. Santiago Porras Rodríguez 75 Reputation points MVP
    2025-03-27T18:31:38.8333333+00:00

    This issue is likely related to how your custom control handles scaling, resolution, and layout adjustments in .NET MAUI. High DPI settings and smaller screens can cause layout elements to behave unpredictably if they aren't designed to adapt dynamically. Here are some steps to address this:

    1. Use Absolute Sizing Where Necessary
    • Relative sizing (e.g., * in Grid definitions) can sometimes lead to unpredictable behavior on high DPI displays. Consider using a mix of absolute and relative sizing to ensure consistent rendering. For example:
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    
    1. Implement Adaptive Layouts

    Use DeviceDisplay.MainDisplayInfo to detect screen size, resolution, and scaling. Adjust your layout dynamically based on these values:

    var displayInfo = DeviceDisplay.MainDisplayInfo;
    var density = displayInfo.Density; // Scale factor
    var width = displayInfo.Width / density;
    var height = displayInfo.Height / density;
    

    You can also subscribe to MainDisplayInfoChanged to handle changes in display settings:

    DeviceDisplay.MainDisplayInfoChanged += (s, e) =>
    {
        var newDisplayInfo = e.DisplayInfo;
        // Adjust layout based on new display info
    };
    
    1. Set IsClippedToBounds
    • Ensure that your custom control or its parent container has IsClippedToBounds set to false to prevent elements from being cut off.
    1. Test with High DPI Settings
    • Use the Windows Display Settings to simulate high DPI scenarios (e.g., scaling above 125%) and observe how your control behaves. Adjust margins, paddings, and alignments accordingly.
    1. Debug with Visual Bounds
    • Use VisualElement.Bounds to debug and ensure your control is being rendered within the expected area:
    Debug.WriteLine($"Control Bounds: {myControl.Bounds}");
    
    1. Consider FlexLayout or AbsoluteLayout
    • If Grid isn't scaling well, try using FlexLayout or AbsoluteLayout for more precise control over positioning and scaling.
    1. Check for DPI-Related Bugs
    • Some issues might be related to known DPI scaling bugs in .NET MAUI. Ensure you're using the latest version of .NET MAUI and check for updates or patches.

    Would you like help implementing any of these solutions? 😊This issue is likely related to how your custom control handles scaling, resolution, and layout adjustments in .NET MAUI. High DPI settings and smaller screens can cause layout elements to behave unpredictably if they aren't designed to adapt dynamically. Here are some steps to address this:

    1. Use Absolute Sizing Where Necessary
    • Relative sizing (e.g., * in Grid definitions) can sometimes lead to unpredictable behavior on high DPI displays. Consider using a mix of absolute and relative sizing to ensure consistent rendering. For example:
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    
    1. Implement Adaptive Layouts

    Use DeviceDisplay.MainDisplayInfo to detect screen size, resolution, and scaling. Adjust your layout dynamically based on these values:

    var displayInfo = DeviceDisplay.MainDisplayInfo;
    var density = displayInfo.Density; // Scale factor
    var width = displayInfo.Width / density;
    var height = displayInfo.Height / density;
    

    You can also subscribe to MainDisplayInfoChanged to handle changes in display settings:

    DeviceDisplay.MainDisplayInfoChanged += (s, e) =>
    {
        var newDisplayInfo = e.DisplayInfo;
        // Adjust layout based on new display info
    };
    
    1. Set IsClippedToBounds
    • Ensure that your custom control or its parent container has IsClippedToBounds set to false to prevent elements from being cut off.
    1. Test with High DPI Settings
    • Use the Windows Display Settings to simulate high DPI scenarios (e.g., scaling above 125%) and observe how your control behaves. Adjust margins, paddings, and alignments accordingly.
    1. Debug with Visual Bounds
    • Use VisualElement.Bounds to debug and ensure your control is being rendered within the expected area:
    Debug.WriteLine($"Control Bounds: {myControl.Bounds}");
    
    1. Consider FlexLayout or AbsoluteLayout
    • If Grid isn't scaling well, try using FlexLayout or AbsoluteLayout for more precise control over positioning and scaling.
    1. Check for DPI-Related Bugs
    • Some issues might be related to known DPI scaling bugs in .NET MAUI. Ensure you're using the latest version of .NET MAUI and check for updates or patches.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.