これらのObservableCollectionを両方ともxamlに実装するにはどうすればよいですか?私はすべての生徒とリストビューを持ちたいと思います。そして、私の先生すべてと一緒にリストビューを作成したいと思います。今はサンプルの生徒と教師のオブジェクトを作成しました。私はこれについて間違った方法をとっていますか?最終的に私はデータテーブルから引き出しますが、どのようにObservableCollectionに実装するのかはわかりません。XAMLで複数の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>
Uは2つの別個のコレクションプロパティを作成するのと同じですか?どのような方法でも私に例を挙げることができますか? :) – TMan
@Tman、正しい。私は例をまとめてここに掲示します、私は通常C#を使用していますので、VB.NET翻訳に最善を尽くします。 –
よろしくお願いします。 – TMan