ビデオで説明する方が簡単なので、問題を撮影しました。リストボックスに、予約テーブルの日付と部屋テーブルの部屋に依存する、予約テーブルから開始した時間を表示したいのですが、それは可能です。
ビデオへのリンクは次のとおりです。 問題のビデオ
生成された XAML は次のとおりです。
<CollectionViewSource x:Key="bookingsViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Booking}, CreateList=True}"/>
<CollectionViewSource x:Key="roomsViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Room}, CreateList=True}"/>
<CollectionViewSource x:Key="roomsBookingsViewSource" Source="{Binding Bookings, Source={StaticResource roomsViewSource}}"/>
<CollectionViewSource x:Key="bookingsBookingsViewSource" Source="{Binding Bookings, Source={StaticResource bookingsViewSource}}"/>
これはグリッド用です:
<Grid x:Name="Grid" SizeChanged="Grid_SizeChanged" Margin="0,0,-0.4,-0.2" DataContext="{StaticResource bookingsViewSource}" >
これはカレンダー用です:
<Calendar x:Name="MainCalendar" Margin="10,135.2,231.8,0" Grid.Row="2" ToolTip="Select a date"
DisplayDateStart="2013-01-01" DisplayDateEnd="2020-01-01" FirstDayOfWeek="Monday" Height="177"
VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" SelectedDatesChanged="datechanged"
DisplayDate="{Binding SelectedDate, RelativeSource={RelativeSource Self}}" SelectedDate="
{Binding Date, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" >
これはコンボボックス用です:
<ComboBox x:Name="roomnameComboBox" Grid.Column="1" DisplayMemberPath="Room.Roomname"
HorizontalAlignment="Left" Height="27" ItemsSource="{Binding}" Margin="3,5,0,0" Grid.Row="0"
VerticalAlignment="Center" Width="120">
そして、これはリストボックス用です:
<ListBox x:Name="listrow" Grid.Column="1" Margin="3.2,1.2,1.8,0" Grid.Row="2"
DisplayMemberPath="Timebegan" SelectionChanged="listrow_SelectionChanged" ItemsSource="{Binding
Source={StaticResource bookingsBookingsViewSource}}"/>
生成された C# は次のとおりです。
private void Bookings_Loaded(object sender, RoutedEventArgs e)
{
var allensCroftEntities1 = new WpfApplication7.AllensCroftEntities1();
// Load data into Bookings. You can modify this code as needed.
var bookingsViewSource = ((CollectionViewSource)(this.FindResource("bookingsViewSource")));
var bookingsQuery = this.GetBookingsQuery(allensCroftEntities1);
bookingsViewSource.Source = bookingsQuery.Execute(MergeOption.AppendOnly);
// Load data into Rooms. You can modify this code as needed.
var roomsViewSource = ((CollectionViewSource)(this.FindResource("roomsViewSource")));
var roomsQuery = this.GetRoomsQuery(allensCroftEntities1);
roomsViewSource.Source = roomsQuery.Execute(MergeOption.AppendOnly);
}
private ObjectQuery<Booking> GetBookingsQuery(AllensCroftEntities1 allensCroftEntities1)
{
var bookingsQuery = allensCroftEntities1.Bookings;
// To explicitly load data, you may need to add Include methods like below:
// bookingsQuery = bookingsQuery.Include("Bookings.Client").
// For more information, please see http://go.microsoft.com/fwlink/?LinkId=157380
// Update the query to include Room.Bookings data in Bookings. You can modify this code as needed.
bookingsQuery = bookingsQuery.Include("Room.Bookings");
// Returns an ObjectQuery.
return bookingsQuery;
}
private ObjectQuery<Room> GetRoomsQuery(AllensCroftEntities1 allensCroftEntities1)
{
var roomsQuery = allensCroftEntities1.Rooms;
// Update the query to include Bookings data in Rooms. You can modify this code as needed.
roomsQuery = roomsQuery.Include("Bookings");
// Returns an ObjectQuery.
return roomsQuery;
}
編集
これは、私があなたのコードを使用したときに起こることです。理由はわかりますか? ところで、これには where コマンドがありません。
編集 where の提案も試しましたが、スクリーンショットでまだこの問題が発生しています: