Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF textbox binding disappears after navigating forward and back again

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.

like image 658
StefK Avatar asked Mar 03 '11 12:03

StefK


1 Answers

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.

like image 92
Emond Avatar answered Oct 23 '22 03:10

Emond