2013-03-16 46 views
4

我拍攝了我的問題,因爲它更容易在視頻中解釋。我希望列表框顯示從預訂表開始的時間,該時間表依賴於預訂表和房間表中的房間的日期,這是可能的。在日曆和組合框中獲取列表框綁定VIDEO

這裏是視頻鏈接:Video of Problem

這裏是生成的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命令。 booking query

編輯 我也嘗試了其中的建議,但我仍然得到的截圖這個問題: Where problem

+1

實際上hamoudy didnt給予好評此,我很驚訝,當它得到了upvied – user2178133 2013-03-16 22:37:37

+1

我剛剛看完你的視頻。我知道你可能認爲視頻可以讓你更容易理解這個問題,但是我認爲它的長度會推遲試圖幫助你的人 – failedprogramming 2013-03-16 22:41:33

+1

謝謝,我已經批准你的更改,但是你是否理解這個問題? – user2178133 2013-03-16 22:56:36

回答

0

有日期和房間綁定屬性在VM上,每當他們改變,得到從數據庫的數據基於這兩者,更新綁定到第三列(應用程序中心的一個)的可觀察集合。

確保所有提出正確的通知,你應該設置。 我有一個類似的解決方案,基於兩個組合框過濾和一些文本框取決於上述選擇,它工作正常。

(和喜歡@failedprogramming說,這是一個漫長的視頻... :)