Rati_Ge
Rati_Ge

Reputation: 1270

How to Use Usercontrol more than once inside one Control

I created WPF UserControl which enables to enter some information now I have Main entry form where I want to use tow instances of that UserControl When I add my YserControl as Resource and than try to use it as ContrntControl's Content exception is thrown informing that control is already a logical child. Can anyone provide with sollution?

Upvotes: 0

Views: 154

Answers (2)

Colin Smith
Colin Smith

Reputation: 12530

You can use the x:Shared attribute so that whenever something references the resource, a new instance is created instead of it being shared.

Thus you might have something like this:

<Window.Resources>
    <MyUserControl x:Key="MyControlKey" x:Shared="False" .... />
    ....
</Window.Resources>

Upvotes: 1

Rati_Ge
Rati_Ge

Reputation: 1270

I just found out way to not throw exception but I want to know if this is right sollution

            <TaicoControl:WizardPage Title="Title1"
                                 BackButtonVisibility="Collapsed"
                                 CancelButtonVisibility="Collapsed"
                                 Description="Desctiption1"
                                 PageType="Interior">
            <ContentPresenter ContentTemplate="{StaticResource PersonEntryFormTemplate}" DataContext="{Binding Person}" />
        </TaicoControl:WizardPage>
        <TaicoControl:WizardPage Title="Title2"
                                 BackButtonVisibility="Collapsed"
                                 CancelButtonVisibility="Collapsed"
                                 Description="Description2"
                                 NextButtonVisibility="Collapsed"
                                 PageType="Interior">
            <ContentPresenter ContentTemplate="{StaticResource PersonEntryFormTemplate}" DataContext="{Binding Person.ContactPerson}" />
        </TaicoControl:WizardPage>

Upvotes: 0

Related Questions