I have a WPF application with a main window and different pages. On one of the pages (OverzichtPage) I have a text box associated with a DataController (Data). (which is a dependent property on the page code) (Worth mentioning: DataController is Singleton, so the patient must remain the same and cannot disappear.)
public static DependencyProperty data = DependencyProperty.Register("Data", typeof(DataController), typeof(OverzichtPage)); public DataController Data { get { return (DataController)GetValue(data); } set { SetValue(data, value); } } <TextBox Name="naamPatientTxtBox" Text="{Binding Path=Data.Patient.naam, Mode=TwoWay}" DataContext="{Binding ElementName=OP}" />
At first glance, this binding seems to work. When I go to another page by clicking the button
<Button Content="Meer info/ Wijzigen" Click="MeerInfoWijzigenBtn_Click" /> private void MeerInfoWijzigenBtn_Click(object sender, RoutedEventArgs e) { Uri pageFunctionUri = new Uri("View/ZorgTrajectPage1.xaml", UriKind.Relative); NavigationService.Navigate(pageFunctionUri); }
and go back, the snap suddenly stops working. After navigating back, I found out, naamPatientTxtBox.GetBindingExpression (TextBox.TextProperty) .ParentBinding; is empty. Does anyone know why this snap suddenly disappears after navigation? I really don't understand how this is possible.
wpf binding textbox
Stefk
source share