Как сохранить значения после перехода по кадрам - PullRequest
0 голосов
/ 03 марта 2020

Помогите мне с переносом значений между кадрами wpf. У меня есть ползунок, которому нужно настроить размер текста, но когда я меняю страницу, ползунок устанавливает значение по умолчанию, пытался перенести эти данные во внешний текстовый документ, это не помогло.


using System; //code with adjustment slider
using System.Windows;
using System.Windows.Controls;
using System.IO;

namespace Writing_Book
{
    public partial class Font : Page
    {
        public Font()
        {
            InitializeComponent();


        }
        string FileRoad = @"D:\Edit.txt";


        public void FontSizeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double FontSize = FontSizeSlider.Value;

            string FontSizeStr = Convert.ToString(FontSize);


            File.WriteAllText(FileRoad, FontSizeStr);

        }
    }
}

using System; //Textbox Code
using System.Windows;
using System.Windows.Controls;
using System.IO;
using Microsoft.Win32;

namespace Writing_Book
{
    public partial class Main : Page
    {
        public Main()
        {
            InitializeComponent();
            Font font = new Font();
            MainTxt.FontSize = font.FontSize;
        }

        string FileRoad = @"D:\Edit.txt";

        OpenFileDialog openFileDialog = new OpenFileDialog();

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == true)
                MainTxt.Text = File.ReadAllText(openFileDialog.FileName);
            NameOfOpenFile.Text = openFileDialog.FileName;

        }

        private void Button_Click_Save(object sender, RoutedEventArgs e)
        {
            File.WriteAllText(openFileDialog.FileName, MainTxt.Text);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {


            MainTxt.FontSize = Convert.ToDouble(File.ReadAllText(FileRoad));
        }
    }
}

Просто вызов класса и извлечение переменной также не работает. Может быть есть идеи?

Не судите строго мой код, я начинающий

...