[英]PropertyChangedEventArgs FormatException
I have next XAML: 我有下一个XAML:
<TextBlock Text="{Binding Path=Parameter.LocalizedName}"/>
And this code in my View Model: 在我的视图模型中的这段代码:
public FilterParameter Parameter
{
get
{
return this._Parameter;
}
set
{
this._Parameter = value;
base.RaisePropertyChanged("Parameter");
}
}
I do 我做
this.Parameter = newParameter
Why I do I get 为什么我得到
FormatException (Input string was not in a correct format.) FormatException(输入字符串的格式不正确。)
After a call to PropertyChangedEventHandler
? 调用PropertyChangedEventHandler
?
http://oi45.tinypic.com/11trceg.jpg http://oi45.tinypic.com/11trceg.jpg
Inner exception is null. 内部异常为null。 Stack trace loook 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#
WPF is trying to convert System.String to System.Int32 and it fails with FormatException. WPF试图将System.String转换为System.Int32,并且失败并显示FormatException。
You should set custom IValueConverter to your Binding to handle this scenario by, for example, returning some default int value, if string cannot be parsed to int. 您应该将自定义IValueConverter设置为Binding,以处理这种情况,例如,如果无法将string解析为int,则返回一些默认的int值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.