4

我已经拍摄了我的问题,因为它更容易在视频中解释。我希望列表框显示从预订表开始的时间,这取决于预订表中的日期和房间表中的房间,这可能吗?

这是视频的链接:问题视频

这是生成的 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 建议,但我仍然在屏幕截图中遇到这个问题: 哪里有问题

4

1 回答 1

0

让日期和房间绑定到您的 VM 上的属性,并且每当它们发生变化时,从基于两者的数据库中获取您的数据,更新绑定到第三列(应用程序中心的那一列)的可观察集合。

确保所有人都发出正确的通知,你应该做好准备。我有一个类似的基于两个组合框的过滤解决方案,以及一些取决于上述选择的文本框,它工作正常。

(就像@failedprogramming 所说,这是一个很长的视频...... :)

于 2013-10-10T06:20:10.400 回答