I'm starting to study WPF and I have a big question
my WPF project has a Books class, which has several attributes, let's take an example
class libros
{
string atributo1;
string atributo2;
string atributo3;
}
Question 1 -To create a book-type object, that is, make an instance of this class, where should I do it?
ex> books book1 = new books();
When I was working in the console I did it in Main() , but now I don't know where it is, and I don't think it's in MainWindow , which is the window that the program creates by default
I have already tried to initialize the objects in MainWindow.xaml of my wpf project , but the "books" type objects that I create are only seen by the MainWindow block of course,
If someone could help me with the initialization logic in WPF or give me a reference to a website that could help me, thank you very much in advance and sorry if I have something wrong in the writing.
edited > code
public MainWindow() {
Libros Libro0 = new Libros();
Libro0.Identificador = 000000;
Libro0.Titulo = "La metamorfosis";
Libro0.Autor = "Frank Kafka";
Libro0.Editorial = "Tupe";
Libro0.Materia = "Ficcion";
Libro0.CantidadEjemplares = 5;
Libro0.Estado = true;
label1.Content= Libro0.Autor; //exception nullreference
InitializeComponent();
}
HODOR, how's it going? I recommend that you follow the official Microsoft documentation.- https://msdn.microsoft.com/es-es/library/ms752299(v=vs.100).aspx something in Spanish. On the other hand, from console to wpf seems somewhat abrupt to me, you could investigate windows forms with which you will be able to take several concepts to wpf.
Regarding your question 1) The class is instantiated when you need it :>
and with the code