WPF Text Box Linking Disappears After Forward and Backward Navigation

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.

+6
wpf binding textbox
source share
2 answers

Have you tried to set the KeepAlive property to true? You may have run into history / caching issues. Status is not supported automatically.

+6
source share

I would put breakpointat on the Loaded event of the parent container (current window or page), check the DataContext property (does it contain anything?) And try resetting if necessary.

Another idea: set TextBox.DataContext to Data, and then the text Patient.naam, so it will be easier for you to debug it, and also allow you to effectively inherit the DataContext.

0
source share

All Articles