M
M
macintosch202020-05-08 15:10:49
WPF
macintosch20, 2020-05-08 15:10:49

How to move a variable to another page?

You need to transfer the variable to another page and the user too.

private void Button_Click(object sender, RoutedEventArgs e)
        {
           int i = 0;
            if (FirstButton.IsChecked == true)
            {
                i = i + 2;
            }
            else if (SecondButton.IsChecked == true)
            {
                i = i + 1;
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-05-08
@firedragon

Here's an example for you. Create an instance common to the entire application, store only the data you need in it and call it as needed

public class DataContext
    {
        private static readonly object Lock = new object();
        private static DataContext _ctx;
        private static SQLiteAsyncConnection _database;
        private static SQLiteAsyncConnection _userDatabase;

        public static DataContext Instance
        {
            get
            {
                lock (Lock)
                {
                    if (_ctx != null) return _ctx;
                    var filePathOnPlatform = GetFilePathOnPlatform(Settings.DataBaseName);
                    var userDb = GetFilePathOnPlatform(Settings.UserDatabaseName);
                    _ctx = new DataContext(filePathOnPlatform, userDb); 
                    return _ctx;
                }
            }
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question