I’m getting an error when I run this code on the physical phone, but not on the emulator:
System.ArgumentException “The parameter is incorrect”
when I use the following code. This is a custom type I created to allow me to easily create types that can Bind to the View.
The exception is thrown on this line:
this.PropertyChanged(this, new PropertyChangedEventArgs("Value"));
This worked perfectly fine until I made it Generic:
public class BindableType<T> : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private T _value;
private T _previousValue;
public T Value
{
get
{
return _value;
}
set
{
_previousValue = _value;
_value = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Value"));
}
}
}
public T PreviousValue
{
get { return _previousValue; }
}
}
Here is the binding code:
Here is the stack trace:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at
MS.Internal.XcpImports.SetValue(IManagedPeerBase obj,
DependencyProperty property, Double d) 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.RefreshExpression(DependencyProperty
dp) at System.Windows.Data.BindingExpression.RefreshExpression()
at System.Windows.Data.BindingExpression.SendDataToTarget() at
System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener
sender, PropertyPathChangedEventArgs args) at
System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep
source) at
System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener
source) at
System.Windows.CLRPropertyListener.SourcePropertyChanged(Object
sender, PropertyChangedEventArgs args) at
System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object
sender, PropertyChangedEventArgs args) at
RoadCast.Model.BindableType1.set_Value(Double value) at1 args) at
RoadCast.Default.locationHelper_PositionChangedMinor(Object sender,
GeoPositionChangedEventArgs
RoadCast.Core.LocationHelper.watcher_PositionChanged(Object sender,
GeoPositionChangedEventArgs`1 e) at
System.Device.Location.GeoCoordinateWatcher.<>c_DisplayClass1.b_0(Object
_) at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo
rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object
parameters, CultureInfo culture, Boolean isBinderDefault, Assembly
caller, Boolean verifyAccess, StackCrawlMark& stackMark) at
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, StackCrawlMark& stackMark) at
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args) at
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at
System.Delegate.DynamicInvoke(Object[] args) at
System.Windows.Threading.DispatcherOperation.Invoke() at
System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority
priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object
context) at System.Windows.Hosting.CallbackCookie.Invoke(Object[]
args) at
System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr
pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam&
pResult)
UPDATE: Renaming the Property to “InternalValue” fixed this for me.
you need to initialize your PropertyChanged to this: