karlrock-1270 avatar image
1 Vote"
karlrock-1270 asked ·

UWP User Control Question

I don't know if this is the right place to ask this question but I am sort of desperate because I can't find this simple thing anywhere so here I go:

I am trying to create an UWP User Control for the first time. One very basic thing I want is automatic Width and Height based on the content of the user control. Simple enough in theory, but whenever I build the control and drop it on a form, it has this default "Width=100" value. Same thing with the Height.

Here is the simple XAML code i have so far:

          <TextBlock HorizontalAlignment="Left" Margin="10,32,0,0" Text="TextBlock" TextWrapping="Wrap" VerticalAlignment="Top"/>

But when I drag the control to a page this is what I get:

<local:JTreeItem HorizontalAlignment="Left" Height="100" Margin="247,305,0,0" VerticalAlignment="Top" Width="100"/>

Both the Width and the Height are 100 by default. But why? How can I change this? This seems so simple, yet adding:


Does not solve this. Removing it does not solve it. Any value I put there gets ignored, for example, if I do this:


Nothing happens. I get the same 100 default value for the Width and the Height.

Why is this so not intuitive? There seems to be no syntax errors in the XAML, so what is happening there?

I am using Visual Studio Community 2019.

If any of you can help, I would appreciate it. Thanks in advance!!!

· 3
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you mean when you drag the UserControl to the designer, you want to generate the right values of width and height based on its content? If you remove the Width and Height which are generated when you drag the UserControl to the designer, can the UserControl display well?

0 Votes 0 · ·

When I drag the User Control from the tool box into the Main Page or Form of my UWP test app at DESIGN TIME it automatically places these "default" values on it. If I removed them THERE (on the test app not on the control code) it works as you would expect, and it displays correctly. But doing it that way means that any user of my control would have to manually remove these default values by hand every time they put them on a page/form.. I want to set these values on the control itself, but for some reason this seems to be unnecessarily difficult, because I can't find a way to do it yet. I have tried some things as previously mentioned and I really don't know what else to try.

0 Votes 0 · ·

It is recommended you could submit an issue via the Feedback hub(Click the Start Menu -> Choose Feedback hub app).

0 Votes 0 · ·

0 Answers