I have a WPF-application with a mainwindow and different pages. On one of the pages (OverzichtPage) I have a textBox bound to a DataController (Data). (which is a dependencyProperty on the codebehind of the page) (Might be worth mentioning: the DataController is a Singleton, so that patient is supposed to stay the same and can't disapear..)
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 sight, this binding seems to work. When I navigate to another page by clicking a 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 navigate back, the binding suddenly stops working. I found out after the navigating back, the naamPatientTxtBox.GetBindingExpression(TextBox.TextProperty).ParentBinding; is empty. Does anyone have a clue why this binding suddenly disapears after the navigating? I really don't understand how this is possible.
Have you tried setting the KeepAlive property of the page to true? You might be running into history/caching problems. State isn't autmatically kept.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With