如何修复 Xceed DateTimePicker ArgumentOutOfRangeException 错误 [英] How to fix Xceed DateTimePicker ArgumentOutOfRangeException Error

查看:32
本文介绍了如何修复 Xceed DateTimePicker ArgumentOutOfRangeException 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Xceed DateTimePicker 作为 wpf DataGrid 中所有绑定到 Date 属性的列的控件.每一列的定义如下:

I am using the Xceed DateTimePicker as the control in a wpf DataGrid for all columns that are bound to a Date property. Each of the those columns is defined as follows:

    <DataGrid.Columns>
    <DataGridTemplateColumn
    Header="Charge Date"
    Width="100">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock
                Text="{Binding Path=ChargeDate, StringFormat=yyyy-MM-dd, Converter={StaticResource conDate}}"
                HorizontalAlignment="Center" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <tk:DateTimePicker Value="{Binding Path=ChargeDate}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

我认为这与我的问题无关,但为了完整起见,这里是选择器的样式:

I don't think it is pertinent to my question, but for completeness sake, here is the styling for the pickers:

<Style TargetType="{x:Type tk:DateTimePicker}">
    <Setter Property="TextAlignment" Value="Center" />
    <Setter Property="Minimum" Value="2017-01-01" />
    <Setter Property="DisplayDefaultValueOnEmptyText" Value="False" />
    <Setter Property="ShowButtonSpinner" Value="False" />
    <Setter Property="TimePickerVisibility" Value="Collapsed" />
    <Setter Property="AutoCloseCalendar" Value="True" />
    <Setter Property="Format" Value="Custom" />
    <Setter Property="FormatString" Value="yyyy-MM-dd" />
</Style>

这适用于已填充的数据网格单元格或当我在新行中输入数据时.但是,当我单击现有行中的空单元格时,出现以下异常:

This works for datagrid cells that are already populated or when I am entering data in a new row. However when I click on an empty cell in an existing row, I get the following exception:

System.ArgumentOutOfRangeException: 'SelectedDate value is not valid.'

为什么只有在现有行中输入数据时才会出错?发生此异常时没有执行任何代码隐藏,所以我不知道去哪里寻找问题.

Why is the error only when I am enter data in an existing row? No code-behind is being executed when this exception happens so I don't know where to look for the problem.

推荐答案

我遇到了同样的问题.要解决此问题,请将 ClipValueToMinMax 属性设置为True".这将防止该值低于最小值/高于最大值而不会引发异常.

I had the same issue. To fix this set the ClipValueToMinMax property to "True". This will prevent the value from going below minimum/above maximum without throwing an exception.

<xceed:DateTimePicker Value="{Binding DateTime}"
                      Minimum="{Binding DateTimeMinimum}"
                      Maximum="{Binding DateTimeMaximum}"
                      ClipValueToMinMax="True"/>

这篇关于如何修复 Xceed DateTimePicker ArgumentOutOfRangeException 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆