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

C#
private string _TextBox1 = "Input";
        public string TextBox1
        {
            get
            {
                return _TextBox1;
            }
            set
            {
                _TextBox1 = value;

                NotifyPropertyChanged(nameof(TextBox1));
            }
        }


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


Now I type in some text and Change with that to next Page in my Project:
C#
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:

C#
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:

XML
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?
Posted
Updated 2-Aug-22 7:40am
Comments
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