Uwp - How to make ContentDialog sized to fit content?
In mine ContentDialog
I have StackPanel
with about three controls (vertical orientation). My problem is that the ContentDialog's height extends to the very end of the window, even though its content doesn't even take up half.
I am guessing it might be the problem StackPanel
, but still how can I fix it?
I could set MaxHeight
, but I have to fill it with fixed values ββthat differ for ContentDialog
...
UPDATE
It's in MainPage.xaml (default start page of VS UWP template). The XAML only shows the creation of one button to use, as this event Click
:
private async void Button_Click(object sender, RoutedEventArgs e)
{
DataEntryDialog dialog = new DataEntryDialog();
//Show dialog
await dialog.ShowAsync();
}
DataEntryDialog.xaml:
<ContentDialog
x:Class="App1.Dialogs.UserAccountDataEntryDialog"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="TITLE"
PrimaryButtonText="Save"
SecondaryButtonText="Cancel"
Loaded="ContentDialog_Loaded"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick">
<StackPanel>
<TextBox Header="Username" Margin="0,20,0,0"/>
<PasswordBox Header="Password" Margin="0,12,0,0"/>
<CheckBox Content="Active" Margin="0,12,0,0"/>
</StackPanel>
</ContentDialog>
source to share
Seems like the ContentDialog
default behavior . If you resize the window of a UWP app, you will see that it stretches vertically and horizontally based on the size of the window. I assume this is done on purpose so that your app dialogs are supported across all platforms (desktop, mobile, tablet, xbox, etc.)
source to share