Responsive MAUI Desktop App

Jassim Al Rahma 1,616 Reputation points
2023-02-17T16:18:20.8+00:00

Hi,

How can I have a responsive XAML in MAUI Desktop Apps so when the user changes the screen size it will listen to the changes and automatically adjust?

Thanks,

Jassim

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-02-20T02:59:42.57+00:00

    Hello,

    In MAUI, you can dynamically adjust the size ratio of elements using Grid layouts to achieve responsive layout

    The .NET Multi-platform App UI (.NET MAUI) Grid, is a layout that organizes its children into rows and columns, which can have proportional or absolute sizes.

    Please refer to Grid to get more details.

    For instance, you could use the following code to set two buttons with a width ratio of 1:2, and when the window size changes, the size of the button will also change.

    <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="2*" />
            </Grid.ColumnDefinitions>
            <Button Grid.Column="0" Text="btn1"/>
            <Button Grid.Column="1" Text="btn2"/>
    </Grid>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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