Entity Framework 4.0、Observable Collection、およびいくつかの CollectionViewSources を使用する WPF アプリケーションに取り組んでいます。私のフォームには、データをフィルタリングするために使用する2つのテキストボックスがあり、フィルタリングしたものに基づいてリストボックスに表示します。私がする必要があるのは、ユーザーがリストボックスから項目を選択してボタン (「選択」) を押すと、情報が適切なコレクションと共にまったく新しいウィンドウに表示されることです。これまでのところ、私は持っています:
Imports System.Data.Objects
Public Class SearchText
Private db As New CraftingProjectsEntities
Private ProjectsData As ProjectsCollection
Private ProjectViewSource As CollectionViewSource
Private MaterialsViewSource As CollectionViewSource
Private ColoringsViewSource As CollectionViewSource
Private DirectionsViewSource As CollectionViewSource
Private SpecialsViewSource As CollectionViewSource
Private WithEvents ProjectView As ListCollectionView
Private MaterialsView As BindingListCollectionView
Private ColoringsView As BindingListCollectionView
Private SpecialsView As BindingListCollectionView
Private DirectionsView As BindingListCollectionView
Private Sub SearchText_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim query = From r In db.Projects
Where r.Materials.Count > 1
Select r
Me.ProjectViewSource = CType(Me.FindResource("ProjectsViewSource"), CollectionViewSource)
Me.DirectionsViewSource = CType(Me.FindResource("DirectionsViewSource"), CollectionViewSource)
Me.ColoringsViewSource = CType(Me.FindResource("ColoringsViewSource"), CollectionViewSource)
Me.SpecialsViewSource = CType(Me.FindResource("SpecialsViewSource"), CollectionViewSource)
Me.MaterialsViewSource = CType(Me.FindResource("MaterialsViewSource"), CollectionViewSource)
Me.ProjectViewSource.Source = Me.ProjectsData
Me.ProjectView = CType(Me.ProjectViewSource.View, ListCollectionView)
Me.DirectionsView = CType(Me.DirectionsViewSource.View, BindingListCollectionView)
Me.ColoringsView = CType(Me.ColoringsViewSource.View, BindingListCollectionView)
Me.MaterialsView = CType(Me.MaterialsViewSource.View, BindingListCollectionView)
Me.SpecialsView = CType(Me.SpecialsViewSource.View, BindingListCollectionView)
MyLists.ItemsSource = ProjectsData
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim query2 As ObjectQuery(Of Project) = Nothing
Dim query = From p In db.Projects
Select p
If TextBox2.Text.Length > 1 And TextBox1.Text.Length > 1 Then
query2 = query.Where(Function(p) p.Materials.Any(Function(m) m.Material1.ToLower().Contains(Me.TextBox1.Text)) And
p.Materials.Any(Function(m) m.Material1.ToLower().Contains(Me.TextBox2.Text)))
ElseIf TextBox2.Text.Length < 1 And TextBox1.Text.Length > 1 Then
query2 = query.Where(Function(p) p.Materials.Any(Function(m) m.Material1.ToLower().Contains(Me.TextBox1.Text)))
Else
MessageBox.Show("What are you looking for?")
Return
End If
Me.ProjectsData = New ProjectsCollection(query2.ToList(), db)
MyLists.ItemsSource = ProjectsData
End Sub
**Works great through here... Below is where i get lost trying to get the selected item to the new window**
Private Sub btnSelect_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnSelect.Click
Dim mychoice As New MyChoice
Dim selitem = Me.MyLists.SelectedItem
mychoice.ProjectsData = (selitem)
mychoice.Show()
Me.Close()
End Sub
End Class
これを行う方法や、これを行う適切な方法を示す例をどこで見つけることができるかについての考えは、非常に高く評価されます。ありがとう。Adam 申し訳ありません....これが役立つ場合は、MVVM を使用しません。