How do you give a custom control a default size?

Hi, currently I’m trying to give a custom made control a default size by setting the width and height to 100 pixels in C#. I want to set a default size on the control so that it isn’t 0 by 0 pixels when you drag it into the UI Builder, but I want the size to be editable after it has been added to the UI. So far I haven’t got it working the way I intend yet.

I’ve been able to give the control a default size by changing the style in C# inside of the constructor of the control or the Init method from UxmlTraits. With both of these implementations it was not possible to resize the control when it was in the UI Builder, because it seems that the constructor and thus the Init method as well, get called whenever you change the control in any way (including when you change the size).

Is there currently a way to give a custom made control a default size in C# that is editable in the UI Builder afterwards?

We don’t really have a simple way to do this. You can try to hack it by setting the size in a GeometryChangeEvent if and only if the current size is 0, but there’s no way to run code on “creation inside UI Builder”.

We do have defaults for the built-in controls via custom creation functions inside UI Builder for each such control (ie. we give the Button the text “Button” even though that is not something Button specifies). But this code is not open for extensibility yet.

1 Like