0

我创建了 WPF UserControl,现在可以输入一些信息我有主输入表单,我想在其中使用该 UserControl 的两个实例当我将 YserControl 添加为资源而不是尝试将其用作 ContrntControl 时抛出内容异常,通知该控件已经一个合乎逻辑的孩子。任何人都可以提供解决方案吗?

4

2 回答 2

1

您可以使用该x:Shared属性,以便每当引用资源时,都会创建一个新实例而不是共享它。

因此你可能有这样的事情:

<Window.Resources>
    <MyUserControl x:Key="MyControlKey" x:Shared="False" .... />
    ....
</Window.Resources>
于 2012-10-18T23:15:12.340 回答
0

我刚刚找到了不抛出异常的方法,但我想知道这是否是正确的解决方案

            <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>
于 2012-10-18T22:56:54.510 回答