(Silverlight:) What happens in which order when a control is added to the UI at design time in Blend 4 RRS feed

  • Question

  • I would like to have a deeper understanding of what exactly happens in which order when I add a control to the UI at design time in Blend 4.

    This is quite urgent to me, so it would be very very cool if anyone could give some detailed information on that.

    Especially I would like to know, which events fire on the process while I draw a certain control, e.g. a Button, throught left-clicking on the UI at design time and dragging the mouse pointer to define the initial design time size.


    I would like to briefly explain the background of my question:

    I designed a UserControl that shall have a minimum height and a minimum width. The UserControl contains only a single button. I designed a special look for this button in the control template. So that at least the essential Visual elements of the buttons are visible, I specified a minimum height and a minimum width in the template of the button. For example 50 x 50.

    There are two ways to add the UserControl at design time to the UI-surface:

    (1) By double clicking


    (2) By clicking and dragging directly on the design surface

    Alternative 1) is not a problem. The UserControl is added to the design surface with the minimum height and minimum width. In the properties of the control the current width and the current height are displayed (50x50) each with units identified as "auto".

    The problem arises in alternative 2). Once the adorner drawing is greater than "Zero", the UserControl appears immediately in the minimum height and minimum width (50 x 50). But when the UserControl is manually drawn onto the design surface and the draw size is less than the minimum size, the height and width displayed in the properties of the UserControl are those in which it was drawn manually, although it appears with the minimum size. In this case, so the actual displayed size and the size defined in the properties are different.

    This is inconsistent and confusing. That is why I am looking for a solution.

    • Edited by Martin Krüger Thursday, January 20, 2011 12:57 PM Added problem background
    Thursday, January 20, 2011 12:11 PM

All replies

  • Is this question too trivial?
    Friday, January 21, 2011 9:56 AM
  • It is setting the Width and Margin properties as you drag the control.  And the style is setting the MinWidth property.  So both Width and MinWidth are getting set, and MinWidth doesn't actually keep you from setting any Width you want.  Width, MinWidth, and MaxWidth all are used to determine the value of ActualWidth. From the remarks section at http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.minwidth.aspx:

    the order of application for actual width determination is first MinWidth must be honored, then MaxWidth, and finally if each of these are within bounds, Width.

    • Proposed as answer by Leo Bartkus Friday, January 21, 2011 6:00 PM
    Friday, January 21, 2011 5:56 PM
  • Hello Leo, thank you for your reply.

    But I don't think that this Information actually solves my Problem. Because I would like to set width and height to the min values right when the process of manually drawing the control onto the UI is completed (at design time!). Is there a way to accomplish this?

    Saturday, January 22, 2011 5:03 AM
  • Something like this looks pretty good on the artboard, but the xaml is setting the wrong values at design time still

    		public Screen_2()
    			this.SizeChanged += new SizeChangedEventHandler(Screen_2_SizeChanged);
    		public void EnforceSize()
    			this.Width = Math.Max(this.Width, 50);
    			this.Height = Math.Max(this.Height, 50);
    		void Screen_2_SizeChanged(object sender, SizeChangedEventArgs e)

    Another thing that might work to really get it to clamp the value at design time is making an example asset like the Mockups example does for its dialog mockups. 

    Tuesday, January 25, 2011 7:03 PM