【发布时间】:2012-02-04 06:11:15
【问题描述】:
如何在我的 xaml 中实现这两个 ObservableCollections?我想与我的所有学生一起创建一个列表视图,并与我所有的老师一起创建另一个列表视图。现在我只是创建了一个示例学生和教师对象。我是不是走错了路。最终我将从数据表中提取数据,但不确定如何将其实现到 ObservableCollection。
Public Class PersonalViewModel
Public Sub New()
Dim obcollection1 As New ObservableCollection(Of Student)
Dim obcollection2 As New ObservableCollection(Of Teacher)
obcollection1.Add(New Student("W0332309", "Tony", "Thetiger", "Male"))
obcollection2.Add(New Teacher)
'I Cant set datacontext here cause 1.) this isn't a window 2.) I can only set datacontext once anyway
'So how to do it in xaml?
End Sub
End Class
xaml:
<Page.Resources>
<local:PersonalViewModel x:Key="personalviewmodel"></local:PersonalViewModel>
</Page.Resources>
<ListView ItemsSource="{Binding Source= {StaticResource personalviewmodel}}" HorizontalAlignment="Left" Margin="256,42,0,67" Name="ListView1" Width="166" IsSynchronizedWithCurrentItem="True" >
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding FName}" />
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding LName}" />
</GridView>
</ListView.View>
</ListView>
【问题讨论】:
标签: wpf vb.net observablecollection