SilverLight Binding数据无法显示?求高手!
用SilverLight4做ListBox数据绑定时无法显示数据:后台代码如下:PartialPublicClassTestInheritsUserControlPubl...
用SilverLight4做ListBox数据绑定时无法显示数据:
后台代码如下:
Partial Public Class Test
Inherits UserControl
Public Sub New
InitializeComponent()
Init()
End Sub
Private Sub Init()
Dim list As List(Of Person) = New List(Of Person)()
For i As Integer = 1 To 5
Dim person As New Person()
person.Age = i
person.Name = "a" + i.ToString()
list.Add(person)
Next
lboxMain.ItemsSource = list
End Sub
Public Class Person
Public Age As Integer
Public Name As String
End Class
End Class
前台代码如下:
<Grid x:Name="LayoutRoot" Background="White">
<ListBox x:Name="lboxMain" Width="600" Height="300">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Orange" BorderThickness="2" CornerRadius="3">
<StackPanel Width="300" Height="50">
<TextBlock Text="{Binding Name}" FontSize="12"/>
<TextBlock Text="{Binding Age}" FontSize="12"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
控件以及边框都能显示出来,但是始终显示不出数据来? 展开
后台代码如下:
Partial Public Class Test
Inherits UserControl
Public Sub New
InitializeComponent()
Init()
End Sub
Private Sub Init()
Dim list As List(Of Person) = New List(Of Person)()
For i As Integer = 1 To 5
Dim person As New Person()
person.Age = i
person.Name = "a" + i.ToString()
list.Add(person)
Next
lboxMain.ItemsSource = list
End Sub
Public Class Person
Public Age As Integer
Public Name As String
End Class
End Class
前台代码如下:
<Grid x:Name="LayoutRoot" Background="White">
<ListBox x:Name="lboxMain" Width="600" Height="300">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Orange" BorderThickness="2" CornerRadius="3">
<StackPanel Width="300" Height="50">
<TextBlock Text="{Binding Name}" FontSize="12"/>
<TextBlock Text="{Binding Age}" FontSize="12"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
控件以及边框都能显示出来,但是始终显示不出数据来? 展开
展开全部
把你的Person改成这样就可以了:
Public Class Person
Private AgeValue As Integer
Public Property Age() As String
Get
Return AgeValue
End Get
Set(ByVal value As String)
AgeValue = value
End Set
End Property
Private NameValue As String
Public Property Name() As String
Get
Return NameValue
End Get
Set(ByVal value As String)
NameValue = value
End Set
End Property
End Class
Binding只能绑定clr属性,而不能绑定你定义的字段。
Public Class Person
Private AgeValue As Integer
Public Property Age() As String
Get
Return AgeValue
End Get
Set(ByVal value As String)
AgeValue = value
End Set
End Property
Private NameValue As String
Public Property Name() As String
Get
Return NameValue
End Get
Set(ByVal value As String)
NameValue = value
End Set
End Property
End Class
Binding只能绑定clr属性,而不能绑定你定义的字段。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我记得实体类中的字段是不予显现的 能在list中显示的只能是属性
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询