I have a WPF-page (ZorgTrajectPage1.xaml) with a code-behind ZorgTrajectPage1.xaml.cs with a DependencyProperty ZorgtrajectController called Ztc.
The dataContext is set in the Page_Loaded() of ZorgTrajectPage1.xaml:
Ztc = new ZorgTrajectController();
DataContext = Ztc;
It appears that I can access this ZorgTrajectController via binding to look up a integer in this Controller (patientID-variable):
<TextBox Name="textBox1" Text="{Binding Path=PatientID, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
This works perfect. But I also have a comboBox that selects an educatiePakket. When this selection is made, the selectedEducatiePakket is looked up via a LINQ-query and put in a variable in a ZorgTrajectController. This SelectedEducatiePakket is a new instance of a LINQ-class (that has a String-property with it’s name, called naam). I used the following method to fill it up:
SelectedEducatiepakket = SelectedEducatiePakketByID(5);
public educatiepakket SelectedEducatiePakketByID(int id)
{
educatiepakket ep = (from o in db.educatiepakkets
where o.educatiepakket_id == id
select o).Single() as educatiepakket;
return ep;
}
Tthe following:
<TextBox Name="EPNaamTxtbx" Text="{Binding Path=SelectedEducatiepakket.naam, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
doesn’t work. I totally don’t understand why this isn’t working. I’ve made a button which in the code-behind Console.WriteLines information of the Ztc. It says there is a selectedEducatiePakket, but my textbox isn’t showing any information of it.
Does anyone know what I’m doing wrong?
Make sure that
ZorgTrajectControllerimplementsINotifyPropertyChangedand fires thePropertyChangedevent in the setter of theSelectedEducatiePakketproperty. Something like this:If that doesn’t help, run your project under debugger and after the property
SelectedEducatiePakketis supposed to be set look in the Visual Studio’s Output window. There might be some information about binding errors.