N
N
NoName9992020-01-09 21:16:01
WPF
NoName999, 2020-01-09 21:16:01

How can I change the contents of the Label so that it persists after the application is restarted?

Good afternoon, there is a button and a label, I need the name of the label to change when the button is pressed, and when the application is restarted, the label has a new name.
newbie in c#.
did something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp3
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Buttons_Click(object sender, RoutedEventArgs e)
        {
            lbl.Content = "Проверка";
        }
    }
   
}

But in this case, after restarting the program, the label name becomes the previous one.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2020-01-10
@NoName999

For example, save to a file, and read from it at startup.

M
Mirtopir, 2020-01-10
@Mirtopir

Make a variable in properties and write to it. And when loading - load from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question