'save data and open in another class

I've got a litlle problem: How do I get stored data from one model into another? I've got an app which is loading strings from a textbox and I want to save them in my class/ Model Userdata.

public class Userdata
{
    private string _user;
    public string User { get => _user; set => _user = value; }
}

Here is how I read it out from the textbox

private string user;
public string User
{
    get { return user; }
    set
    {
        user = value;
        OnPropertyChanged("User");
    }
}
public Userdata myStrings= new Userdata();

public MyViewModel()
{
    MyCommand = new Relaycommand(o=>
    {
        myStrings.User = User;
        validate(myStrings.User);
    };
}
public bool validate(string user)
{
NpgsqlConnection connectorDatabase = ConnectorDatabase.GetConnection2(server, port, user, password, database);
}

While debugging I get my data into the string so the binding is working. Now is where the problem comes, the data which is stored needs to be readable in the other Models/Class,but I don't know hot to save them properly.

public class ConnectorDatabase
{
    public static NpgsqlConnection GetConnection2(string server, int port, string user, string password, string database)
    {
        Userdata Con = new Userdata();
        return new NpgsqlConnection(@"Server=" + Con.Server + ";Port=" + Con.Port + ";User ID=" + Con.User + ";Password=" + Con.Password + ";Database=" + Con.Database + ";");
    }    
}

Here is my 3rd class where I want to my read data from textbox to be used. But the data is null here, probably because I make a new object of Userdata. So, I kind of know why it's not working, but I want to know how I can make data accessible in multiple viewmodels when it gets stored in strings. I don't know if it will work if I use a list, and I rather don't want to save them in a local file and open them everytime I use them.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source