Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this Property:

private string _TextBox1 = "Input";
        public string TextBox1
                return _TextBox1;
                _TextBox1 = value;


I placed it like that:
Text="{Binding TextBox1, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"

Now I type in some text and Change with that to next Page in my Project:
PagesNavigation.Navigate(new System.Uri("/EttiketPage.xaml", UriKind.RelativeOrAbsolute));

But now the Text I wrote get erased and the normal "Input" line is back.

What I have tried:

I know the ViewModel creates more then one Instance which it could be erased. To avoid that I created an ApplicationService class with that:

public sealed class ApplicationService
        private ApplicationService() { }

        public static ApplicationService Instance { get; } = new ApplicationService();

        public ViewModel PrintView { get; } = new ViewModel();

And in every Page I placed this DataContext:

DataContext="{Binding PrintView, Source={x:Static local:ApplicationService.Instance}}"

But for some reason the data of the Property get erased every time I change the Page, someone an Idea?
Updated 2-Aug-22 6:40am
Graeme_Grant 2-Aug-22 10:39am    
Object lifetime. Set a breakpoint in the construction of the VM and look at the stack trace in the debug window. You can see why.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900