gpt4 book ai didi

sql - 获取绑定(bind)在日历和组合框视频上的列表框

转载 作者:太空狗 更新时间:2023-10-30 01:58:21 24 4
gpt4 key购买 nike

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

这是视频的链接: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 建议,但我在屏幕截图中仍然遇到这个问题: Where problem

最佳答案

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

确保所有人都发出正确的通知,然后你就应该准备好了。我有一个类似的解决方案,用于基于两个组合框和一些文本框(取决于上述选择)进行过滤,并且效果很好。

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

关于sql - 获取绑定(bind)在日历和组合框视频上的列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15455443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com