Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimePicker的SelectedTime在绑定时报错 #1348

Closed
hdzs opened this issue Feb 9, 2023 · 4 comments
Closed

TimePicker的SelectedTime在绑定时报错 #1348

hdzs opened this issue Feb 9, 2023 · 4 comments

Comments

@hdzs
Copy link

hdzs commented Feb 9, 2023

Describe the bug

使用Stylet框架,在xaml上绑定SelectedTime到属性上时,报错“Object reference not set to an instance of anobject.”。在项目启动后热重载编辑绑定信息时可用。

Steps to reproduce the bug

Expected behavior

No response

Screenshots

image

NuGet package version

HandyControl 3.4.0

IDE

Visual Studio 2022

Framework type

.Net 5.0

Windows version

No response

Additional context

No response

@MiyamuraMiyako
Copy link

@NaBian 您好,我这边升级到3.4后也同样遇到这个问题,非Binding也不行:
图片

@AscendantWare
Copy link

hi,

the Error is still happening.
Here is the Stacktrace:

by HandyControl.Controls.TimePicker.CoerceSelectedTime(DependencyObject d, Object value)
by System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
by System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
by System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
by System.Windows.DependencyObject.SetCurrentValue(DependencyProperty dp, Object value)
by HandyControl.Controls.TimePicker.SetSelectedTime()
by HandyControl.Controls.TimePicker.OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
by System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
by System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
by System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
by System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
by System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
by System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
by System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
by MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
by MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
by MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.SetValue(Object obj, XamlMember property, Object value)
by System.Xaml.XamlObjectWriter.SetValue(Object inst, XamlMember property, Object value)
by System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
by System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
by System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
by System.Xaml.XamlObjectWriter.WriteEndObject()
by System.Xaml.XamlWriter.WriteNode(XamlReader reader)
by System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
by System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
by System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
by System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
by System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
by AscendantScheduler.MVVM.Views.JobDetailView.InitializeComponent() in F:\Projekte\SVN\Entwicklungen\Sonstiges\AscendantScheduler\trunk\AscendantScheduler\AscendantScheduler\MVVM\Views\JobDetailView.xaml: Zeile1
by AscendantScheduler.MVVM.Views.JobDetailView..ctor() in F:\Projekte\SVN\Entwicklungen\Sonstiges\AscendantScheduler\trunk\AscendantScheduler\AscendantScheduler\MVVM\Views\JobDetailView.xaml.cs: Zeile25
by System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

@asine
Copy link
Contributor

asine commented Jun 4, 2023

same error too

@apris-zhangpp
Copy link

I found the problem in the following code,
private static object CoerceSelectedTime(DependencyObject d, object value)
{
var dp = (TimePicker) d;
dp.Clock.SelectedTime = (DateTime?) value;
return dp.Clock.SelectedTime;
}
When we bind to select time in xaml, the Clock is null.

I found a solution If we execute this method EnsureClock(); in the constructor, we can solve this problem

@NaBian NaBian closed this as completed in 4af5be7 Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants