2

I have a stackpanel where I have a checkbox and a textblock defined in the xaml, I then add alot of dynamicly created controlls during runtime, and then add these with the stackpanel.children.add(controll) .

The problem is that I want to add all my dynamicly created controlls on top of the ones defined in the xaml. How can I do this in the best way ?

Thanks

1 Answer 1

2

Have you tried using stackPanel.Children.Insert(0, control)

Sign up to request clarification or add additional context in comments.

3 Comments

yes, the problem is that I have a dynamic method that adds alot of elements to the stackpanel, and I don't know at what index I want to insert all the dynamicly created ones into.
@Fore: Silverlight makes no distinction between "dynamic" and "static". Since you know that the first "dynamic" control you add should be inserted above all the existing controls you can use the code Vixen has posted. You will then have to keep track of the number of controls you've added dynamically so far. That way you will know at what index to insert the next one.
@AnthonyWJones: Hello, I guess you mean that when I add the dynamicly generated contolls that I add the .Insert to them ? I was thinking that I might be able to add the checkbox and textblock dynamicly, and then I will just add them last in my dynamicly adding code. But the I get problems with some methods that are dependent on the checkbox name, but shouldn't I be able to "find" my new generated checkbox instead of having it in the xaml and adding it from there? I hope you understand what I mean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.