Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get UWP content dialog to size properly

Tags:

dialog

size

uwp

I can't get my UWP dialogs to exceed some fixed width. This app has been in production a few years, but after this last update, the dialogs are all some strange fixed width. I am using MVVM light and did just update to 5.4.1 but I am just calling dialog objects subclassed from ContentDialog. As I mentioned, this has been working just fine for 1.5 years or so, not sure why it just stopped working. Any help would be greatly appreciated. Thanks.

xaml code follows:

SecondaryButtonText="Cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
Width="Auto"
MinWidth="1000"
Opened="ContentDialog_Opened"
Closed="ContentDialog_Closed"
DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=ClockDialog}">

<Grid HorizontalAlignment="Stretch" MinWidth="900">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1.3*"/>
        <ColumnDefinition Width="4*" MinWidth="200"/>
        <ColumnDefinition Width="1.3*"/>
        <ColumnDefinition Width="4*" MinWidth="200"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <StackPanel Orientation="Vertical">
        <TextBlock Margin="0,6" Text="Type:" Style="{StaticResource CCBlackTextBlock}" HorizontalAlignment="Right"/>
        <TextBlock Margin="0,8"  Text="Mfg:" Style="{StaticResource CCBlackTextBlock}" HorizontalAlignment="Right"/>
like image 518
Tom Lindley Avatar asked Feb 21 '18 05:02

Tom Lindley


3 Answers

As noted by @Tom, I copied the MaxWidth and MaxHeight keys into the App Resources, and changed to my desired values. No other parts of the style were needed.

<Application.Resources>
    <x:Double x:Key="ContentDialogMaxWidth">1200</x:Double>
    <x:Double x:Key="ContentDialogMaxHeight">800</x:Double>
like image 89
Bob Krauth Avatar answered Oct 13 '22 21:10

Bob Krauth


The default Style for ContentDialog imposes a MaxHeight of 184 and MaxWidth of 548: https://msdn.microsoft.com/en-us/library/windows/apps/mt299120.aspx

Perhaps this was added or changed in the update like you suspect. To override the style properties try something like:

<Grid Name="MyContainer">
    <Grid.Resources>
        <Style TargetType="ContentDialog" x:Key="largeDialaog">
            <Setter Property="MaxHeight" Value="720" />
            <Setter Property="MaxWidth" Value="1280" />
        </Style>
    </Grid.Resources>
    <ContentDialog Style="{StaticResource largeDialog}">
        <!--your content goes here-->
    </ContentDialog>
</Grid>
like image 36
Sean O'Neil Avatar answered Oct 13 '22 21:10

Sean O'Neil


Based on the previous response, I started looking at the style for ContentDialog. I could not find a default style using blend, so just decided to create my own. All I did was copy the style posted here Documented style for ContentDialog to my own style library and then applied it to all my ContentDialog screens. That did the trick and I am back in business. I suspect that something is missing from the latest VS update I applied just a few days ago.

like image 33
Tom Lindley Avatar answered Oct 13 '22 22:10

Tom Lindley