cannot change the size of a dialog

Eduardo Gomez 3,431 Reputation points
2023-07-06T12:59:45.74+00:00

I manage to display a dialog, passing a XamlRoot from the view to the view model

     ViewModel = viewModel;
            viewModel.xamlRoot = Content.XamlRoot;

            ExtendsContentIntoTitleBar = true;
            SetTitleBar(AppBar);

            var rootElement = Content as FrameworkElement;
            if (rootElement != null) {

                rootElement.Loaded += (s, e) => {
                    var root = Content.XamlRoot;
                    if (root != null) {
                        viewModel.xamlRoot = root;
                    }


View model
   [RelayCommand]
        private async Task OpenRegisterDialogAsync() {

            var registerVM = new RegisterWindowViewModel(_location);
            var registerView = new RegisterWindow(registerVM) {
                XamlRoot = xamlRoot,
            };
            await registerView.ShowAsync();


        }
    }

User's image

<ContentDialog
    x:Class="Demy.View.RegisterWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:demy="using:Demy"
    xmlns:local="using:Demy.View"
    Width="800"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">


    <StackPanel
        Grid.Row="1"
        Width="600"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Spacing="20">

        <TextBox
            PlaceholderText="First name"
            Text="{x:Bind ViewModel.User.Name}" />

        <TextBox
            PlaceholderText="Second name"
            Text="{x:Bind ViewModel.User.SecondName}" />

        <TextBox
            PlaceholderText="Phone Number"
            Text="{x:Bind ViewModel.User.Phone}" />

        <TextBox
            PlaceholderText="Email Address"
            Text="{x:Bind ViewModel.User.Email}" />

        <PasswordBox
            Password="{x:Bind ViewModel.User.Password}"
            PasswordRevealMode="Peek"
            PlaceholderText="Password" />

        <PasswordBox
            Password="{x:Bind ViewModel.User.ConfirmPassword}"
            PasswordRevealMode="Peek"
            PlaceholderText="Confirm password" />

        <Button Command="{x:Bind ViewModel.RegisterAsyncCommand}" />
    </StackPanel>
</ContentDialog>


Cannot change the size

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
822 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 10,531 Reputation points Microsoft Vendor
    2023-07-07T06:34:05.9766667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The default maximum width of ContentDialog is 548. If you want to modify the width of ContentDialog.You could override the theme resource which named ContentDialogMaxWidth to a bigger value.

    For example:

        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                    <!-- Other merged dictionaries here -->
                </ResourceDictionary.MergedDictionaries>
                <!-- Other app resources here -->
                <x:Double x:Key="ContentDialogMaxWidth">800</x:Double>
            </ResourceDictionary>
        </Application.Resources>
    

    Thank you.

    Jeanine


    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Eduardo Gomez 3,431 Reputation points
    2023-07-06T21:12:32.0233333+00:00

    I just answer this

    0 comments No comments

  2. Poramin 0 Reputation points
    2023-07-21T07:54:11.04+00:00

    I'm sorry. I followed the example provided, but it still doesn't work. The size remains at 548 as before. However, if I remove the XamlControlsResources, I can set the ContentDialogMaxWidth, but doing so might cause a bug later.

     <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                </ResourceDictionary.MergedDictionaries>
                <x:Double x:Key="ContentDialogMaxWidth">1200</x:Double>
            </ResourceDictionary>
        </Application.Resources>
    

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.