This project has moved and is read-only. For the latest updates, please go here.

Same User Control in Multiple Form



I have created a complex shipping form containing multiple user controls.
for Example :
A shipping screen containing Recipient User control, Sender User Control, Ship Detail User Control, Billing User Control.

This was working fine until I tried to use few of the user control in some other form as well.

I am getting error message "Specified element is already the logical child of another element. Disconnect it first"

Since I am using WAF framework so I do not want to manually disconnect and connect parent on code behind.

I believe User control is created to use it in multiple forms but it seems WPF does not allow multiple parents without disconnecting previous parent.

Do any one have any suggestion or came up with this issue ?

Thanks in Advance.


jbe2277 wrote Oct 12, 2013 at 9:25 PM

Thank you for your feedback.

This is a limitation of WPF. An instance of a (user) control cannot be reused at another place. If you would like to reuse the control then you have to create a second instance of it.

The Writer sample application reuses the RichTextView user control for every document that is created or opened. This view comes with an own ViewModel.

The Information Manager sample application defines the SearchBox control (see Common.Presentation project). This control is reused by the email views and the address book view. The SearchBox does not have an own ViewModel but it defines dependency properties so that it is easy to bind them to a ViewModel.