AddConstraint for Child Control of Another Control

I have a custom control based on an iOSCanvas that is mimicking a dashboard widget. I want to show an iOSProgressWheel on my widget while it does its thing. Borrowing from the Dynamic Controls example project I am able to add the ProgressWheel by doing a self.AddControl but the ProgressWheel is added at the top left corner of the canvas and I’d like it in the centre.

Attempting to AddConstraint to my iOSCanvas-based control obviously doesn’t work because only iOSViews have this method. Is there a way to centre a dynamically created control within its parent while making the whole thing independent of the parent view?

please file a bug report about this

I modified the dynamic control project slightly by adding a larger rectangle. Then to make rect relative to the the center of Rectangle1, I replaced the left constraint by :

Dim rectCenter As New iOSLayoutConstraint(rect, _ iOSLayoutConstraint.AttributeTypes.CenterX, _ iOSLayoutConstraint.RelationTypes.Equal, _ Rectangle1, _ iOSLayoutConstraint.AttributeTypes.CenterX, _ 1, _ 0) Me.AddConstraint(rectCenter)

The rectangle is horizontally centered relative to its parent Rectangle 1.

create a iOSLayoutConstraint relative to parent for an added sub control is easy
But there is no way to get a trueWindow equivalent (trueView?) to add the iOSLayoutConstraint

Yes @Michel Bujardet I can get this far but the part that doesn’t work in a user control with a super of iOSCanvas is the last line:

Me.AddConstraint(rectCenter)

That’s because “Me” needs to be an iOSView.

[quote=168745:@Antonio Rinaldi]create a iOSLayoutConstraint relative to parent for an added sub control is easy
But there is no way to get a trueWindow equivalent (trueView?) to add the iOSLayoutConstraint[/quote]

Yep. That’s what’s required I think. I’ll use your words in the Feedback case.

[quote=168783:@Jason Tait]Yes @Michel Bujardet I can get this far but the part that doesn’t work in a user control with a super of iOSCanvas is the last line:

Me.AddConstraint(rectCenter)
That’s because “Me” needs to be an iOSView.[/quote]

Instead of trying to add constraints to the canvas, which is not possible, add constraints to the view, but make your dynamic control constraints relative to the canvas. That’s all it is to it.

Thank you Michel and, yes, I can do this but with respect that wasn’t my question which, admittedly, was clumsily worded. :).

There does not seem to be a way to access the true parent as Antonio has pointed out and this may be a deficiency as Norman has suggested filing a bug report.

[quote=168792:@Jason Tait]
There does not seem to be a way to access the true parent as Antonio has pointed out and this may be a deficiency as Norman has suggested filing a bug report.[/quote]

I agree the word “parent” in the constraints is inadequate, as soon as the control is child of another control.

I tend to consider it is a poor choice of words more than a bug. Maybe instead of Parent they should have used “Self”.

In desktop, Left and Top always refer to Self. If a control is child of a canvas, it will still have left and top measured towards the window or ContainerControl left and top.

I tend to find it more logical that all constraints be attached to the view, but could be made relative to a specific control. It would quickly become unmanageable if one had to figure which is “Parent” in the IDE, since constraints are added to the view, but for all intents and purpose act as properties of the control. To make it even worse, several controls can become parents : Canvas, ImageView, HTMLViewer, iOSTable…

Auto Layout is confuse enough for some, without adding the notion of “which parent” with for sole help a pretty discrete red outline.

I am looking forward for the notion of subview, though, which pretty much like a container control may have it’s own set of constraints. But hopefully it will be, just as Container Controls, not mixed up with other controls on the view.