以下XAML(下面)定義資源中的自定義集合,並嘗試用自定義對象填充它;如何解決WPF設計器錯誤'類型{0}不支持直接內容'。'?
<UserControl x:Class="ImageListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300"
xmlns:local="clr-namespace:MyControls" >
<UserControl.Resources>
<local:MyCustomCollection x:Key="MyKey">
<local:MyCustomItem>
</local:MyCustomItem>
</local:MyCustomCollection>
</UserControl.Resources>
</UserControl>
的問題是,我得到了「類型‘MyCustomCollection的設計者是一個錯誤’不支持直接的內容」。我已經嘗試設置ContentProperty建議在MSDN中,但無法弄清楚要設置它。我使用的自定義集合對象如下,非常簡單。我試過Item,Items和MyCustomItem,想不到還有什麼可以嘗試的。
<ContentProperty("WhatGoesHere?")> _
Public Class MyCustomCollection
Inherits ObservableCollection(Of MyCustomItem)
End Class
任何關於我哪裏出錯的線索都會感激不盡。同時也提示如何深入研究WPF對象模型以查看運行時暴露的屬性,我可能也可以通過這種方式來弄清楚。
問候
瑞安
看起來不錯,但關於你的二傳手的問題在那裏。難道這不會不斷加入集合並導致異常? 另外,爲什麼IList和不是ObservableCollection? 謝謝 – 2008-12-10 17:08:59