C# PropertyChangedEventArgs格式异常

C# PropertyChangedEventArgs格式异常,c#,.net,xaml,formatexception,C#,.net,Xaml,Formatexception,我有下一个XAML: <TextBlock Text="{Binding Path=Parameter.LocalizedName}"/> 我知道 为什么我会这样 FormatException(输入字符串的格式不正确。) 调用属性ChangedEventHandler后 内部异常为空。 堆栈跟踪look-like mscorlib.dll!System.Number.StringToNumber(string str, System.Globalization.NumberS

我有下一个XAML:

<TextBlock Text="{Binding Path=Parameter.LocalizedName}"/>
我知道

为什么我会这样

FormatException(输入字符串的格式不正确。)

调用
属性ChangedEventHandler


内部异常为空。 堆栈跟踪look-like

mscorlib.dll!System.Number.StringToNumber(string str, System.Globalization.NumberStyles options, ref System.Number.NumberBuffer number, System.Globalization.NumberFormatInfo info, bool parseDecimal) + 0xf7 bytes 
mscorlib.dll!System.Number.ParseInt32(string s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) + 0x92 bytes   
mscorlib.dll!string.System.IConvertible.ToInt32(System.IFormatProvider provider) + 0x2f bytes   
mscorlib.dll!System.Convert.ChangeType(object value, System.Type conversionType, System.IFormatProvider provider) + 0x1ff bytes 
PresentationFramework.dll!MS.Internal.Data.SystemConvertConverter.Convert(object o, System.Type type, object parameter, System.Globalization.CultureInfo culture) + 0x11 bytes  
PresentationFramework.dll!MS.Internal.Data.DynamicValueConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + 0x51 bytes 
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.VerifyEqual(object knownValue, System.Type knownType, object itemValue, MS.Internal.Data.DynamicValueConverter converter) + 0x64 bytes    
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.FindItemWithValue(object value, out int index) + 0x1f7 bytes  
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.SelectItemWithValue(object value) + 0x3e bytes    
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.CoerceSelectedValue(System.Windows.DependencyObject d, object value) + 0x91 bytes 
WindowsBase.dll!System.Windows.DependencyObject.ProcessCoerceValue(System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, ref System.Windows.EntryIndex entryIndex, ref int targetIndex, ref System.Windows.EffectiveValueEntry newEntry, ref System.Windows.EffectiveValueEntry oldEntry, ref object oldValue, object baseValue, object controlValue, System.Windows.CoerceValueCallback coerceValueCallback, bool coerceWithDeferredReference, bool coerceWithCurrentValue, bool skipBaseValueChecks) + 0x55 bytes   
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x247 bytes   
WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue) + 0xd1 bytes    
PresentationFramework.dll!System.Windows.StyleHelper.InvalidateDependents(System.Windows.Style ownerStyle, System.Windows.FrameworkTemplate frameworkTemplate, System.Windows.DependencyObject container, System.Windows.DependencyProperty dp, ref MS.Utility.FrugalStructList<System.Windows.ChildPropertyDependent> dependents, bool invalidateOnlyContainer) + 0x79 bytes   
PresentationFramework.dll!System.Windows.StyleHelper.OnBindingValueInTemplateChanged(object sender, MS.Internal.Data.BindingValueChangedEventArgs e) + 0xe2 bytes   
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ChangeValue(object newValue, bool notify) + 0x94 bytes  
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange) + 0x40c bytes 
PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange) + 0x3a bytes    
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange) + 0x60 bytes 
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange) + 0x211 bytes 
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(object o, string propName) + 0x85 bytes 
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + 0x68 bytes   
WindowsBase.dll!System.Windows.WeakEventManager.ListenerList<System.ComponentModel.PropertyChangedEventArgs>.DeliverEvent(object sender, System.EventArgs e, System.Type managerType) + 0x12c bytes 
WindowsBase.dll!System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args) + 0x40c bytes   
>   MyApp.Framework.Core.dll!MyApp.Framework.Core.NotifyObject.RaisePropertyChanged(string propertyName) Line 45 + 0x32 bytes   C# 
mscorlib.dll!System.Number.StringToNumber(字符串str,System.Globalization.NumberStyles选项,参考System.Number.NumberBuffer Number,System.Globalization.NumberFormatInfo,bool parseDecimal)+0xf7字节
mscorlib.dll!System.Number.ParseInt32(字符串s,System.Globalization.NumberStyles样式,System.Globalization.NumberFormatInfo)+0x92字节
mscorlib.dll!string.System.IConvertible.ToInt32(System.IFormatProvider)+0x2f字节
mscorlib.dll!System.Convert.ChangeType(对象值、System.Type conversionType、System.IFormatProvider提供程序)+0x1ff字节
PresentationFramework.dll!MS.Internal.Data.SystemConvertConverter.Convert(对象o,系统类型,对象参数,系统全球化,文化信息文化)+0x11字节
PresentationFramework.dll!MS.Internal.Data.DynamicValueConverter.Convert(对象值,系统类型targetType,对象参数,系统全球化.CultureInfo区域性)+0x51字节
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.VerifyEqual(对象knownValue,系统类型knownType,对象itemValue,MS.Internal.Data.DynamicValueConverter)+0x64字节
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.FindItemWithValue(对象值,out int index)+0x1f7字节
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.SelectItemWithValue(对象值)+0x3e字节
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.PresideSelectedValue(System.Windows.DependencyObject d,object value)+0x91字节
WindowsBase.dll!System.Windows.DependencyObject.ProcessImpresseValue(System.Windows.DependencyProperty dp、System.Windows.PropertyMetadata、ref System.Windows.EntryIndex EntryIndex、ref int targetIndex、ref System.Windows.EffectiveValueEntry newEntry、ref System.Windows.EffectiveValueEntry oldEntry、ref object oldValue、object baseValue、object controlValue、System.Windows.CommerceValueCallback CommerceValueCallback、bool-convertewithdeferredreference、bool-convertewithcurrentvalue、bool-skipBaseValueChecks)+0x55字节
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex EntryIndex、System.Windows.DependencyProperty dp、System.Windows.PropertyMetadata、System.Windows.EffectiveValueEntry oldEntry、ref System.Windows.EffectiveValueEntry newEntry、bool强制WithDeferedReference、bool强制WithCurrentValue、System.Windows.OperationType OperationType)+0x247字节
WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp,bool preserveCurrentValue)+0xd1字节
PresentationFramework.dll!System.Windows.StyleHelper.InvalidateDependents(System.Windows.StyleOwnerStyle,System.Windows.FrameworkTemplate FrameworkTemplate,System.Windows.DependencyObject容器,System.Windows.DependencyProperty dp,ref MS.Utility.FrugalStructureList dependents,bool invalidateOnlyContainer)+0x79字节
PresentationFramework.dll!System.Windows.StyleHelper.OnBindingValueInTemplateChanged(对象发送方,MS.Internal.Data.BindingValueChangedEventArgs e)+0xe2字节
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ChangeValue(对象newValue,bool notify)+0x94字节
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(对象newValue,bool isSubpertyChange)+0x40c字节
PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isSubpertyChange)+0x3a字节
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependenceSourcesChanged,bool initialValue,bool isSubpertyChange)+0x60字节
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k,System.ComponentModel.ICollectionView collectionView,object newValue,bool IsSubpertyChange)+0x211字节
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(对象o,字符串propName)+0x85字节
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.OnPropertyChanged(对象发送方,System.ComponentModel.PropertyChangedEventArgs e)+0x68字节
WindowsBase.dll!System.Windows.ventManager.ListenerList.DeliverEvent(对象发送方,System.EventArgs e,System.Type managerType)+0x12c字节
WindowsBase.dll!System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(对象发送方,System.ComponentModel.PropertyChangedEventArgs参数)+0x40c字节
>MyApp.Framework.Core.dll!MyApp.Framework.Core.NotifyObject.RaisePropertyChanged(string propertyName)行45+0x32字节C#

WPF正在尝试将System.String转换为System.Int32,但由于FormatException失败


您应该将自定义IValueConverter设置到绑定以处理此情况,例如,如果字符串无法解析为int,则返回一些默认的int值。

查看内部异常。它必须是其他异常。FilterParameter.LocalizeName看起来像什么?堆栈跟踪是什么?可能是附加到PropertyChanged事件w的某个异常我把它扔了exception@Roman--没有足够的信息来解决这个问题--我们需要查看内部异常和stack trace.Hm,但是为什么WPF会这样做(尝试转换)?调用mscorlib.dll!System.Number.StringToNumber的原因是什么?我只想调用RaisePropertyChanged with string parameter.WPF attached PropertyChangedEventHandler到PropertyChanged事件,以便它可以在属性更改时更新UI。您可能已将此属性(或其子属性)绑定到其他控件(使用Int32 DependencyProperty)文本块除外。搜索Google或StackOverf
this.Parameter = newParameter
mscorlib.dll!System.Number.StringToNumber(string str, System.Globalization.NumberStyles options, ref System.Number.NumberBuffer number, System.Globalization.NumberFormatInfo info, bool parseDecimal) + 0xf7 bytes 
mscorlib.dll!System.Number.ParseInt32(string s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) + 0x92 bytes   
mscorlib.dll!string.System.IConvertible.ToInt32(System.IFormatProvider provider) + 0x2f bytes   
mscorlib.dll!System.Convert.ChangeType(object value, System.Type conversionType, System.IFormatProvider provider) + 0x1ff bytes 
PresentationFramework.dll!MS.Internal.Data.SystemConvertConverter.Convert(object o, System.Type type, object parameter, System.Globalization.CultureInfo culture) + 0x11 bytes  
PresentationFramework.dll!MS.Internal.Data.DynamicValueConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + 0x51 bytes 
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.VerifyEqual(object knownValue, System.Type knownType, object itemValue, MS.Internal.Data.DynamicValueConverter converter) + 0x64 bytes    
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.FindItemWithValue(object value, out int index) + 0x1f7 bytes  
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.SelectItemWithValue(object value) + 0x3e bytes    
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.CoerceSelectedValue(System.Windows.DependencyObject d, object value) + 0x91 bytes 
WindowsBase.dll!System.Windows.DependencyObject.ProcessCoerceValue(System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, ref System.Windows.EntryIndex entryIndex, ref int targetIndex, ref System.Windows.EffectiveValueEntry newEntry, ref System.Windows.EffectiveValueEntry oldEntry, ref object oldValue, object baseValue, object controlValue, System.Windows.CoerceValueCallback coerceValueCallback, bool coerceWithDeferredReference, bool coerceWithCurrentValue, bool skipBaseValueChecks) + 0x55 bytes   
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x247 bytes   
WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue) + 0xd1 bytes    
PresentationFramework.dll!System.Windows.StyleHelper.InvalidateDependents(System.Windows.Style ownerStyle, System.Windows.FrameworkTemplate frameworkTemplate, System.Windows.DependencyObject container, System.Windows.DependencyProperty dp, ref MS.Utility.FrugalStructList<System.Windows.ChildPropertyDependent> dependents, bool invalidateOnlyContainer) + 0x79 bytes   
PresentationFramework.dll!System.Windows.StyleHelper.OnBindingValueInTemplateChanged(object sender, MS.Internal.Data.BindingValueChangedEventArgs e) + 0xe2 bytes   
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ChangeValue(object newValue, bool notify) + 0x94 bytes  
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange) + 0x40c bytes 
PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange) + 0x3a bytes    
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange) + 0x60 bytes 
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange) + 0x211 bytes 
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(object o, string propName) + 0x85 bytes 
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + 0x68 bytes   
WindowsBase.dll!System.Windows.WeakEventManager.ListenerList<System.ComponentModel.PropertyChangedEventArgs>.DeliverEvent(object sender, System.EventArgs e, System.Type managerType) + 0x12c bytes 
WindowsBase.dll!System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args) + 0x40c bytes   
>   MyApp.Framework.Core.dll!MyApp.Framework.Core.NotifyObject.RaisePropertyChanged(string propertyName) Line 45 + 0x32 bytes   C#