Resizing canvas after dynamically adding controls at runtime RRS feed

  • Question

  • I have a custom activity which I am dynamically adding controls ( text box, other custom activities, etc. ) in the checked event of a check box.

    The check box is within a canvas object. The controls successfully get added, however the canvas does not resize to accomodate them. They visually extend beyond the borders of the activity they are being added to.

    Is there a way to have the canvas object resize itself?

    Here's the code I use to add the objects to the canvas:

          TextBox testTextBox = new TextBox();
          RadioButton testRadioButton = new RadioButton();
          StackPanel testPanel = new StackPanel();
          CustomAndOrActivity testAndOr = new CustomAndOrActivity();
          ModelItem canvasActivity = this.ModelItem;
          object droppedItem = testAndOr;
          ModelItem droppedModelItem = canvasActivity.Properties["Children"].Collection.Add(droppedItem);
          var viewAndOr = Context.Services.GetService<ViewService>().GetView(droppedModelItem);



    Monday, May 24, 2010 7:02 PM

All replies

  • The WPF Canvas control , which I think is the type of the control you are talking about is, does not automatically resize itself. There are some ways using standard WPF technique (nothing WF specific) that you can get it to do autoresize by Binding its Width and Height properties to your own custom dependency properties, etc.

    And there are other strategies
    -listen for drop and set width/height in your drop handler
    -implement your own custom panel class which supports autoresize

    I don't know a best.


    Wednesday, June 23, 2010 4:20 PM