You create a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The application tracks stock prices in real time. You need to bind a label to the Price property of the Stock class. You also need to ensure that the label reflects any change in the Price property.
Which code segment should you use?
A.
public class Stock : DependencyObject
{
private decimal _price;
public decimal Price
{
get { return _price; }
set { _price = value; }
}
}
B.
public class Stock : DependencyObject
{
public static readonly DependencyProperty PriceProperty = DependencyProperty.Register("Price", typeof(decimal), typeof(Stock));
public decimal Price
{
get { return (decimal)GetValue(Stock.PriceProperty); }
set { SetValue(Stock.PriceProperty, value); }
}
}
C.
public class Stock
{
public event EventHandler PropertyChanged;
private decimal _price;
public decimal Price
{
get { return _price; }
set
{
_price = value;
if (PropertyChanged != null)
PropertyChanged(this, EventArgs.Empty)
}
}
}
D.
public class Stock
{
public event PropertyChangedEventHandler PropertyChanged;
private decimal _price;
public decimal Price
{
get { return _price; }
set
{
_price = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Price"));
}
}
}