简体   繁体   中英

error with list of usercontrol in wpf

I create a wpf app with several UserControls and in one of them I want have a list of another usercontrol, I used from observable collection that manage easy it but when I add item to this list in designer and build solution, user control gone and show error.

Cannot create an instance of " Component".

Exception: Cannot create an instance of " Component".

errors: The component Project. Component' does not have a resource identified by the URI '/ Project;component/component.xaml'.

I create observableCollection and if I create observableCollection problem be solved but I need to collection of my userControl. When I run app I haven't problem and only in designer problem occurred.

Edited:

   public partial class my_Component : UserControl
    {

        private ObservableCollection<user_Component> userCollection;
        public ObservableCollection<user_Component> UserCollection
        {
            get { return userCollection; }
        }
        public my_Component()
        {
            userCollection = new ObservableCollection<user_Component>();
        }


In xaml:
    <cc:my_Component >
        <cc:my_Component.userCollection>
            <cc:user_Component/>
        </cc:my_Component.userCollection>
    </cc:my_Component>

通过使用ObservableCollection的'DependencyProperty'解决了此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM