请问,我使用datagrid嵌套datepicker,第一次点击选择时间,可以返回给C#的list,可是我再次点击重新选择一个时间,list里面的StartDate并没有更新,还是原来最初的那个时间。
代码如下:
- <DataGrid>
- <DataGrid.Columns>
- <DataGridTextColumn Header="批次号" Binding="{Binding Path=BatchCode,Mode=TwoWay}" IsReadOnly="False" Width="280" ></DataGridTextColumn>
- <DataGridTemplateColumn Header="开始时间" Width="150">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <DatePicker Name="datePickerStartTimeNew" Text="{Binding Path=StartDate,Mode= TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Center"</DatePicker>
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- </DataGrid.Columns>
- </DataGrid>
复制代码
- public class WorkOrderInfo
- {
- public DateTime StartDate { get; set; }
- public string BatchCode { get; set; }
- public WorkOrderInfo(DataRow dr)
- {
- StartDate = Convert.ToDateTime(dr["StartDate"]);
- BatchCode = Convert.ToString(dr["BatchCode"]);
- }
- }
- //新建一个list,用来获取datagrid里面的时间
- List<WorkOrderInfo> WorkOrderInfoListCurrent = new List<WorkOrderInfo>();
- //初始化list ,并给datagrid赋值
- this.dgProdOrder.ItemsSource = null;
- this.dgProdOrder.ItemsSource = workOrderInfoListCurrent;
- //点击页面修改时间workOrderInfoListCurrent只发生一次变化,多次修改时间,workOrderInfoListCurrent的StartDate并不刷新
复制代码 |
|