gpt4 book ai didi

c# - INotifyPropertyChanged 在 silverlight c# 中频繁调用时出错

转载 作者:行者123 更新时间:2023-11-30 18:00:59 24 4
gpt4 key购买 nike

我已经创建了一个基本 View 模型来将我所有 View 模型的所有通用属性放入其中,并且它正在由我的 C# Silverlight 应用程序的所有 View 模型实现。

我的基本 View 模型还为所有 View 模型实现了 INotifyPropertyChanged 接口(interface)。

public event PropertyChangedEventHandler PropertyChanged;

protected void NotifyPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

当我频繁调用 PropertyChanged 事件时,出现错误:

Error HRESULT E_FAIL has been returned from a call to a COM component.

堆栈跟踪是

   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)   at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)   at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)   at System.Windows.Controls.Control.set_DefaultStyleKey(Object value)   at System.Windows.Controls.ContentControl..ctor()   at MS.Internal.CoreTypes.GetCoreWrapper(UInt32 typeId)   at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference)   at MS.Internal.XcpImports.ConvertDO(IntPtr doPointer, Int32 typeIndex, Boolean releaseObjectReference)   at MS.Internal.XcpImports.ConvertType(CValue outVal, Int32 typeIndex, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject)   at MS.Internal.XcpImports.ConvertCValueForManagedWithType(Type propertyType, CValue& outVal, Int32 outDOType, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject)   at MS.Internal.XcpImports.GetValue(IManagedPeerBase managedPeer, DependencyProperty property)   at System.Windows.DependencyObject.GetValueInternal(DependencyProperty dp)   at System.Windows.FrameworkElement.GetValueInternal(DependencyProperty dp)   at System.Windows.FrameworkElement.get_Parent()   at Telerik.Windows.RadRoutedEventHelper.FindParent(FrameworkElement item)   at Telerik.Windows.RadRoutedEventHelper.BuildRoute(DependencyObject element, EventRoute route, RadRoutedEventArgs args)   at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)   at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)   at Telerik.Windows.Controls.Selector.OnSelectionChanged(SelectionChangedEventArgs e)   at Telerik.Windows.Controls.RadComboBox.OnSelectionChanged(SelectionChangedEventArgs e)   at Telerik.Windows.Controls.Selector.OnSelectionChanged(Object sender, SelectionChangedEventArgs e)   at Telerik.Windows.Controls.Selector.SelectionChanger`1.InvokeSelectionChangedEvent()   at Telerik.Windows.Controls.Selector.SelectionChanger`1.End()   at Telerik.Windows.Controls.Selector.SelectionChanger`1.SelectJustThisItem(T item)   at Telerik.Windows.Controls.Selector.SelectItemWithValue(Object value)   at Telerik.Windows.Controls.Selector.CoerceSelectedValue(Object value)   at Telerik.Windows.Controls.Selector.OnCoerceSelectedValue(DependencyObject sender, Object newValue)   at Telerik.Windows.PropertyMetadata.DoCoercion(Func`3 areValuesEqual, DependencyObject d, DependencyProperty dp, CoerceValueCallback coerceCallback, Object defaultBaseValue, Boolean forceNewBaseValue, Boolean& isReentrantImplicitCoercion)   at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)   at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)   at System.Windows.Data.BindingExpression.SendDataToTarget()   at System.Windows.Data.BindingExpression.SourceAcquired()   at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.<BreakOnSharedType>b__3()

最佳答案

没有发现您的 INotifyPropertyChanged 实现有任何问题,但是我怀疑您的代码以某种方式导致了无限循环。

如果您可以共享一个可以重现您遇到的问题的示例项目,人们可能会帮助您。

关于c# - INotifyPropertyChanged 在 silverlight c# 中频繁调用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9552794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com