向前和向后导航后,WPF文本框绑定消失

Ste*_*efK 6 wpf binding textbox

我有一个带有主窗口和不同页面的WPF应用程序.在其中一个页面(OverzichtPage)上,我有一个绑定到DataController(Data)的textBox.(这是页面代码隐藏的dependencyProperty)(可能值得一提的是:DataController是一个Singleton,所以患者应该保持不变并且不能消失...)

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}" />
Run Code Online (Sandbox Code Playgroud)

乍一看,这种绑定似乎有效.当我通过单击按钮导航到另一个页面时

<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);
    }
Run Code Online (Sandbox Code Playgroud)

并导航回来,绑定突然停止工作.我在导航回来后发现了naamPatientTxtBox.GetBindingExpression(TextBox.TextProperty).ParentBinding; 是空的.有没有人知道为什么这个绑定在导航后突然消失了?我真的不明白这是怎么回事.

Ern*_*rno 6

您是否尝试将页面的KeepAlive属性设置为true?您可能遇到了历史/缓存问题.国家不是自动保留的.