locked
scrollviever not able to add childeren controls during runtime.. RRS feed

  • Question

  • below are steps that i recived from a friend in order to help me get a usercontrol appear to the right the user control , the basically the usercontrol consists a bunch of textboxes and buttons like this picture....

    http://www.flickr.com/photos/14529949@N07/3262167943/in/photostream/

    but my friend who is very busy now, and not able to help me silly assumed that this is a stack panel but infact it is not it is a scrollviewver


    1.       Create a new UserControl in your project. Put all the controls that you have within the rectangle in it (The image shows some controls in the rounded black rectangle).

    2.       Save the Usercontrol with the name ucGrid.

    3.       Save the project . Build it.

    4.       Dynamically create this UserControl when you click the “Add Child” button.

    Example code for when the “Add Child” button is clicked:

     

    ucGrid uc=new ucGrid();

    uc.SetValue(NameProperty,”grid1”);

    stk.Children.Add(uc);

     

    In the above code I am assuming that you have a StackPanel named stk and that has its Orientation property set to Horizontal.

    5.       The above sample code will dynamically create a grid named grid1 and add it to the stackpanel.

    6.       When you want to remove an item from the stackpanel you can select the item in the stackpanel and then click on the “Remove Child” button. This way you will be able to get the name of the usercontrol that is clicked and you can then remove it.


    so now i am stuck on how to change the code so that it will be able to work i tried everything a newbie could think of but i really need help thanks


    D.Boy
    Thursday, February 26, 2009 11:31 AM