开发者

The type{0} does not support direct content - WPF / XAML

I defined in my code two classes: a "Person" class with public "Age" and "Name" property, and a "People" class that inherits from Generic.List(of T).

The code for People class is as followed:

Public Class People
    Inherits Collections.Generic.List(Of Person)

    ...
End Class

What I want to achieve is to directly initialize the People class, and add individual Person to it in XAML, i.e.:

<local:People x:Key="Familty">
        <local:Person Age="11" Name="John" />          
        <local:Person Age="12" Name="John2" />
        ...
</local:People> 

But I keep getting an error in XAML saying: The type 'People' does not support direct co开发者_如何学Gontent.

Any idea as for how to solve this problem?

Thank you very much!


What exactly do you want to do?

It seams that you try set a content to a control (that must be a ContentControl / or inherited class). Also please notice that you are setting the Content in xaml, that means the it must be a UIElement at least.

If you want to represent a list of people, please set a dataTemplate to that dataType and have a visual representation, then set the ItemsSource (of People which should be a items Control) to a list (or observable collection) of people.

You should consider separating the UI from the model.

So, what exactly are you trying to do ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜