Disabling automatic re-sizing of workspace add-ins

The Problem

You want to add a control to the table that so often exists at the top of a workspace. So you create a label and a workspace config to allow it's width to be adjusted. You then meticulously count pixels until your label fits perfectly with the other labels already in the column. (This could probably be considered a defect, or at least a very nice to have enhancement). However, once you load your workspace with a record the size of your label is off.

Workspace Config

Workspace Control


As you can see here that the size jumps around all over the place. It starts at 117 for unknown reasons, then goes to the default size, then goes to the configured size (or close) and then finally gets resized to something smaller, again for unknown reasons. The problem isn't fatal, a good admin could continually resize the control and test the changes until the workspace finally looked correct, however that is not a great solution.

The Solution

It's actually surprisingly simple, just add the following to your workspace control:
/// /// by overloading this we can ensure that the workspace doesn't try to rescale our control (and throw off our width) /// protected override bool ScaleChildren { get { return false; } } All we're doing is telling the control not to allow any of it's children to be scaled. Now when we load our workspace it only uses the width defined in the workspace config.
Full Source can be found on bitbucket under Tutorials / AddIns / ControlResizing /

Comments

Hi Jack,

but what happens if the admin changes the label Organization to Organization1? Then it is probably off again, right? Is there no way to place it in tables or something that will be automatically scaled with the rest of the workspace?

Bastiaan

yep it will definitely be the wrong size if the label gets changed and I'm not aware of any sanctioned way to make it automatically the correct size based on other labels in the table (my assumption is that normal fields are placed in a 2 column table, with the first column auto-sized, but that an add-in gets it's column span set to 2). there might be a way to walk up the control hierarchy and determine the column size, but for the majority of workspaces this works well enough (and labels change infrequently enough)

Zircon - This is a contributing Drupal Theme
Design by WeebPal.