簡體   English   中英

wpf中的usercontrol列表錯誤

[英]error with list of usercontrol in wpf

我用幾個UserControl創建了一個wpf應用程序,其中一個我想要一個其他usercontrol的列表,我從可觀察的集合中使用它來管理它很容易,但是當我在設計器中將項目添加到此列表中並構建解決方案時,用戶控件就消失了錯誤。

無法創建“組件”的實例。

例外: 無法創建“組件”的實例。

錯誤: 組件項目。 組件”沒有URI“ / Project; component / component.xaml”標識的資源。

我創建了observableCollection,如果創建了observableCollection,則可以解決問題,但需要收集userControl。 當我運行應用程序時,我沒有問題,只有設計器問題發生了。

編輯:

   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'解決了此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM