我正在尝试通过属性将数据绑定到 DataGrid,然后更新该属性以更改(排序)数据网格中的结果。
我最初绑定 DataGrid:
BindingList<Booking> tourBookings;
private async void PageFrame_Loaded_1(object sender, RoutedEventArgs e) {
tourBookings = new BindingList<Booking>((await DataManager.BookingsRef.GetBookingHeaders(PageSize, CurrentPage)).TourBookings);
dgBookings.DataContext = tourBookings;
}
此时 DataGrid 中没有任何内容,无论哪种方式我都有一个排序方法:
private async void DataGrid_Sorting_1(object sender, DataGridSortingEventArgs e) {
tourBookings = new BindingList<Booking>((await DataManager.BookingsRef.GetBookingHeaders(s, asc, PageSize, CurrentPage)).TourBookings);
}
..我的数据网格中仍然没有结果...
我的结果在哪里?
这也是我的绑定:
<DataGrid x:Name="dgBookings" DataContext="{Binding Path=tourBookings}" Style="{StaticResource DataGridStyle}" AutoGenerateColumns="False" CanUserAddRows="False"
ScrollViewer.PanningMode="VerticalOnly" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"
ScrollViewer.PanningDeceleration="5" ScrollViewer.PanningRatio="1" Grid.RowSpan="2"
Grid.Row="1" RowEditEnding="DataGrid_RowEditEnding_1" CanUserSortColumns="True" Sorting="DataGrid_Sorting_1">
<DataGrid.Columns>
<DataGridTemplateColumn Width="*" SortMemberPath="Time" SortDirection="Ascending">
<DataGridTemplateColumn.Header>
Time
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding StartTime, StringFormat=HH:mm}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" SortMemberPath="TourID">
<DataGridTemplateColumn.Header>
Tour ID 1
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding TourID}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
..... and load of other properties and then close datagrid.columns etc