This is my first question. I have been looking at this issue for about a whole day, but I canโt understand why this binding does not work.
I want the label to display the name of the "hotspot" object, which is a property of an instance of the class named Plan. There are several plans, and each plan contains several hot spots. When I click on an access point, the property Plan.SelectedHotSpotsets this hotspot with a click as a value. If HotSpot is not selected, it will be zero.
XAML:
<Label Name="lblHotSpotName" />
MainWindow code when Plan is selected from a ListBox:
private void lstPlans_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
canvas.Plan = PlanBLL.GetPlanByID(plans[lstPlans.SelectedIndex].ID);
lblHotSpotName.DataContext = canvas.Plan;
lblHotSpotName.SetBinding(Label.ContentProperty, "SelectedHotSpot.Name");
}
Planning Class:
public class Plan : INotifyPropertyChanged
{
private HotSpot selectedHotSpot;
public HotSpot SelectedHotSpot
{
get { return selectedHotSpot; }
set
{
selectedHotSpot = value;
OnPropertyChanged("SelectedHotSpot");
OnPropertyChanged("SelectedHotSpot.Name");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
, lblHotSpotName, .
, SelectedHotSpot NULL hotspot, .
? , , . , Plan.SelectedHotSpot.
.