0

I have a UserControl that I want to add at runtime to my current WPF Page. Is this possible?

Having a Menu-bar and under it i want to have all my information, i.e. that i select Menu -> Show Orders then I want the OrderList-UserControl to be added under the Menu.

Sure I could use an Order WPF Page for that but then I'd have to re-create the Menu everywhere? And I don't like the redundancy in that.

I tried something like this which didn't display anything at all, it sure did run the code inside the UserControl but nothing is displayed on my window:

wrapPanel1.Children.Add(new OrderControl(100));

Suggestions?

1 Answer 1

2

If you put a ContentPresenter as a placeholder you can set the Content property of that control to a control generated in codebehind.


Strange, looking at the code in this link what you are doing should work correctly - and the code I gave you definitely works in my app - so I guess there is something wrong either with your custom control or the screen redraws. Can you add the control directly in XMAL and see it? What happens if you add the control through code behind then force a screen redraw (cover the window with another and then uncover it).

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

Comments

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.