我有一个日期选择器控件,其代码,样式和堆栈跟踪如下。问题可以在客户端重现,但是如果我尽力尝试,那么重现该问题就不会成功。
<controls:DatePicker x:Name="dtpDatedue"
Grid.Row="5"
Grid.Column="2"
Margin="5 0 0 0"
TabIndex="9"
VerticalAlignment="Center"
SelectedDate="{Binding Path=Datedue,
Mode=TwoWay,
NotifyOnValidationError=True}"
Style="{StaticResource DatePickerStyle}" />
Style:-
<Style x:Key="DatePickerStyle" TargetType="controls:DatePicker">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Background" Value="#FFFFFFFF" />
<Setter Property="Padding" Value="2" />
<Setter Property="SelectionBackground" Value="#FF444444" />
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush StartPoint=".5,1" EndPoint=".5,0">
<GradientStop Offset="0" Color="#FF617584" />
<GradientStop Offset="0.375" Color="#FF718597" />
<GradientStop Offset="0.375" Color="#FF8399A9" />
<GradientStop Offset="1" Color="#FFA3AEB9" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:DatePicker">
<Grid x:Name="Root">
<Grid.Resources>
<SolidColorBrush x:Key="DisabledBrush" Color="#8CFFFFFF" />
<ControlTemplate x:Key="DropDownButtonTemplate" TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
<VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
<VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#FF448DCA" />
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#FF448DCA" />
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="Highlight"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0" Value="1" />
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="0"
Duration="00:00:00.001"
Storyboard.TargetName="DisabledVisual"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Width="19"
Height="18"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="#11FFFFFF">
<Grid.RowDefinitions>
<RowDefinition Height="23*" />
<RowDefinition Height="19*" />
<RowDefinition Height="19*" />
<RowDefinition Height="19*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Border x:Name="Highlight"
Grid.Row="0"
Grid.RowSpan="4"
Grid.ColumnSpan="4"
Margin="-1"
BorderBrush="#FF6DBDD1"
BorderThickness="1"
CornerRadius="0,0,1,1"
Opacity="0" />
<Border x:Name="Background"
Grid.Row="1"
Grid.RowSpan="3"
Grid.ColumnSpan="4"
Margin="0,-1,0,0"
Background="#FF1F3B53"
BorderBrush="#FFFFFFFF"
BorderThickness="1"
CornerRadius=".5"
Opacity="1" />
<Border x:Name="BackgroundGradient"
Grid.Row="1"
Grid.RowSpan="3"
Grid.ColumnSpan="4"
Margin="0,-1,0,0"
BorderBrush="#BF000000"
BorderThickness="1"
CornerRadius=".5"
Opacity="1">
<Border.Background>
<LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1">
<GradientStop Offset="0" Color="#FFFFFFFF" />
<GradientStop Offset="0.375" Color="#F9FFFFFF" />
<GradientStop Offset="0.625" Color="#E5FFFFFF" />
<GradientStop Offset="1" Color="#C6FFFFFF" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Rectangle Grid.RowSpan="1"
Grid.ColumnSpan="4"
StrokeThickness="1">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0.48,1.25" EndPoint="0.48,-1">
<GradientStop Color="#FF494949" />
<GradientStop Offset="1" Color="#FF9F9F9F" />
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.46,1.6" EndPoint="0.3,-1.1">
<GradientStop Color="#FF4084BD" />
<GradientStop Offset="1" Color="#FFAFCFEA" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Path Grid.Row="1"
Grid.RowSpan="3"
Grid.Column="0"
Grid.ColumnSpan="4"
Margin="4,3,4,3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z"
Fill="#FF2F2F2F"
RenderTransformOrigin="0.5,0.5"
Stretch="Fill" />
<Ellipse Grid.ColumnSpan="4"
Width="3"
Height="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="#FFFFFFFF"
StrokeThickness="0" />
<Border x:Name="DisabledVisual"
Grid.Row="0"
Grid.RowSpan="4"
Grid.ColumnSpan="4"
BorderBrush="#B2FFFFFF"
BorderThickness="1"
CornerRadius="0,0,.5,.5"
Opacity="0" />
</Grid>
</Grid>
</ControlTemplate>
</Grid.Resources>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="DisabledVisual"
Storyboard.TargetProperty="Opacity"
To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="Valid" />
<VisualState x:Name="InvalidUnfocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="InvalidFocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>True</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<System_Windows_Controls_Primitives:DatePickerTextBox x:Name="TextBox"
Grid.Column="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
TextAlignment="Right"
SelectionBackground="{TemplateBinding SelectionBackground}" />
<Button x:Name="Button"
Grid.Column="1"
Width="20"
Margin="2,0,2,0"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Foreground="{TemplateBinding Foreground}"
Template="{StaticResource DropDownButtonTemplate}" />
<Grid x:Name="DisabledVisual"
Grid.ColumnSpan="2"
IsHitTestVisible="False"
Opacity="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Fill="#8CFFFFFF"
RadiusX="1"
RadiusY="1" />
<Rectangle Grid.Column="1"
Width="19"
Height="18"
Margin="2,0,2,0"
Fill="#8CFFFFFF"
RadiusX="1"
RadiusY="1" />
</Grid>
<Popup x:Name="Popup" />
<Border x:Name="ValidationErrorElement"
BorderBrush="#FFDB000C"
BorderThickness="1"
CornerRadius="1"
Visibility="Collapsed">
<ToolTipService.ToolTip>
<ToolTip x:Name="validationTooltip"
DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right"
PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ValidationToolTipTemplate}">
<ToolTip.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsHitTestVisible">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>true</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ToolTip.Triggers>
</ToolTip>
</ToolTipService.ToolTip>
<Grid Width="12"
Height="12"
Margin="1,-4,-4,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="Transparent">
<Path Margin="1,3,0,0"
Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
Fill="#FFDC000C" />
<Path Margin="1,3,0,0"
Data="M 0,0 L2,0 L 8,6 L8,8"
Fill="#ffffff" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
错误堆栈跟踪:
异常类型:System.InvalidOperationException异常StackTrace:bij MS.Internal.XcpImports.VisualStateManager_GoToState(控件参考,字符串StateName,布尔型useTransitions,布尔值和refreshInheritanceContext)bij System.Windows.VisualStateManager.GoToState(控件,字符串状态名,布尔值useTransitions )bij System.Windows.Controls.VisualStates.GoToState(控制控件,布尔useTransitions,String [] stateNames)bij System.Windows.Controls.Primitives.CalendarDayButton.ChangeVisualState(Boolean useTransitions)bij System.Windows.Controls.Primitives.CalendarItem。 SetButtonState(CalendarDayButton childButton,DateTime dateToAdd)bij System.Windows.Controls.Primitives.CalendarItem.SetCalendarDayButtons(DateTime firstDayOfMonth)bij System.Windows.Controls.Primitives.CalendarItem.UpdateMonthMode()bij System.Windows.Controls.Calendar.UpdateMonths bij System.Windows.Controls.SelectedDatesCollection.ClearItems()bij System.Collections.ObjectModel.Collection`1.C lear()bij System.Windows.Controls.Calendar.OnSelectedDateChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)bij System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp,Object oldValue,Object newValue)bij System.Windows.DependencyObject(UpdateEperfectiveValue EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,ValueOperation操作)System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp,Object value,Boolean allowReadOnlySet,Boolean isBindingInStyleSetter)bij System.Windows.Controls.DatePicker.OnSelectedDateChanged(DependencyObjectProd。 Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp,Object oldValue,Object newValue)bij System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty属性,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,ValueOperation操作)bij系统。 Windows.DependencyObject.RefreshExpression(DependencyProperty dp)bij System.Windows.Data.BindingExpression.SendDataToTarget()bij System.Windows.Data.BindingExpression.SourceAcquired()bij System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(对象发件人,DataContextChangedEventArgs e)bij System.Windows.Data.BindingExpression.DataContextChanged(对象发件人,DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)附件System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)附件System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)附件System.Windows.FrameworkElement.OnAncestorDataContextChanged(Data se)bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.dOnArgsData bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAnssContextContextd .Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.NotifyDataContextCh anged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs.Windows DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)bij System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp)Bij System.Windows。 ,对象oldValue,对象newValue)bij System.Windows.Depe,System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty属性,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,ValueOperation操作) ndencyObject.SetValueInternal(DependencyProperty dp,Object value,Boolean allowReadOnlySet,Boolean isBindingInStyleSetter)