1

I'm trying to build a UserControl in a UWP application and I'm not able to see its "Auto" size (based on its content) in the XAML-Designer.

I'm aware I can hardcode d:DesignHeight and d:DesignWidth to absolute values, but since the size should be based on its content, I don't want to hardcode the values.

Is there something like d:DesignHeight="Auto" / d:DesignWidth="Auto" ?

E.g. - for the sample User Control below

<UserControl
    x:Class="MyCompany.UserControls.MyUserControl1"
    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:local="using:MyCompany.UserControls.UserControls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <StackPanel>
        <Button Content="First" />
        <Button Content="Second" />
    </StackPanel>
</UserControl>

I'm seeing

enter image description here

However I'd like to see the size of the control based on its content.

2 Answers 2

0

Unfortunately, this is a limitation of the XAML designer. The control will still be sized properly at runtime.

However, this is a very good feedback and I suggest you send it as enhancement request in through Visual Studio feedback, I would definitely upvote it :-) .

2
0

If delete d:DesignHeight & d:DesignWidth in user control, it will layout as to it's content.

if it doesn't, then you can add VerticalAlignment & HorizontalAlignment to your user control while using.

<local:MyUserControl2  VerticalAlignment="Top" HorizontalAlignment="Left" 
    BorderBrush="Red" BorderThickness="1"/>

It should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.