Can anyone tell me why PropertyChanged
value comes null in INotifyPropertyChanged
. I have a property and I change its value, but when it enters in NotifyPropertyChanged
method the value of PropertyChanged is null. Following is my code :
public class WorkOrder : INotifyPropertyChanged
{
public string _orderDays="0 Days";
public string OrderDays
{
get { return _orderDays; }
set
{
if (_orderDays == value)
return;
_orderDays = value;
NotifyPropertyChanged("OrderDays");
}
}
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
public void NotifyPropertyChanged([CallerMemberName]String propertyName =null )
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
this is the xaml where I bind the value
<Label x:Name="lblTicketDate" Text="{Binding OrderDays}"
Grid.Row="1" HorizontalOptions="CenterAndExpand"
VerticalOptions="EndAndExpand" />
but when it enters in NotifyPropertyChangd method the value of PropertyChanged is null
That just means that nothing has subscribed to the event yet. Beyond events, a delegate instances refers to one or more actions to execute when the delegate is invoked - a null reference is used to represent "0 actions".
If you use:
var order = new WorkOrder();
// Or whatever's useful instead of Console.WriteLine
order.PropertyChanged += (sender, args) => Console.WriteLine(e.PropertyName);
order.OrderDays = "Different";
then you'll see the event being raised.
See more on this question at Stackoverflow