WPF,DataGrid提交中的C#Datepicker

时间:2019-03-22 07:18:54

标签: c# wpf datagrid datepicker

我对DatePicker中的Datagrid有疑问。 当我更改创建的日期在行中时-可见是可以的,但是当我读取数据时有旧值。我必须转到另一个单元格并按Enter,然后确定。

如何自动提交更改?哪个活动?我尝试了不同的活动..和CommitEdit,但暂时没有任何帮助。 谢谢

我的XAML:

<DataGrid x:Name="dg_work" HorizontalAlignment="Left" Height="142" Margin="11,396,0,0" VerticalAlignment="Top" Width="927" AutoGenerateColumns="False" PreviewKeyDown="dg_work_PreviewKeyDown" AddingNewItem="dg_work_AddingNewItem" CanUserAddRows="True" CanUserDeleteRows="True" Grid.ColumnSpan="2">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Id" Binding="{Binding Ident}" />
                        <DataGridTemplateColumn Header="Datum">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <DatePicker SelectedDate="{Binding Datum}" BorderThickness="0" SelectedDateChanged="DatePicker_SelectedDateChanged" CalendarClosed="DatePicker_CalendarClosed" TouchEnter="DatePicker_TouchEnter" TextInput="DatePicker_TextInput" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Arbeitszeit-Beginn" Binding="{Binding VonP}" />
                        <DataGridTextColumn Header="Arbeitszeit-Ende" Binding="{Binding BisP}" />
                        <DataGridTextColumn Header="Rüstzeit" Binding="{Binding Rzeit}" />
                        <DataGridTextColumn Header="Pause" Binding="{Binding Pzeit}" />
                        <DataGridTextColumn Header="Übernachtung" Binding="{Binding Ubern}" />
                        <DataGridTextColumn Header="Anfahrts-Zeit" Binding="{Binding ANZeit}" />
                        <DataGridTextColumn Header="Anfahrts-KM" Binding="{Binding ANkm}" />
                        <DataGridTextColumn Header="Rückfahrts-Zeit" Binding="{Binding RFzeit}" />
                        <DataGridTextColumn Header="Rückfahrts-KM" Binding="{Binding RFkm}" />
                        <DataGridTextColumn Header="Zusatzinfos" Binding="{Binding Zinfo}" />

                    </DataGrid.Columns>
                </DataGrid>

在C#中:

        private void DatePicker_CalendarClosed(object sender, RoutedEventArgs e)
    {
        dg_work.CommitEdit();
    }

    private void DatePicker_TouchEnter(object sender, TouchEventArgs e)
    {
        dg_work.CommitEdit();
    }

    private void DatePicker_TextInput(object sender, TextCompositionEventArgs e)
    {

        dg_work.CommitEdit();
    }

0 个答案:

没有答案