C # Basic Doubt of WPF

0

I'm starting to study WPF and I have a big doubt

my project WPF has a Books class, which has several attributes, let's say an example

class libros
{
string atributo1;
string atributo2;
string atributo3;
}

question 1 - to create a book type object, that is, to make an instance of this class, where should I do it?

  

ej > books libro1 = new books ();

When I was working on the console I was doing it in the Main () , but now I do not know where it is, and I do not think it's in MainWindow which is the window that creates defect the program

I have already tried to initialize the objects in MainWindow.xaml of my project wpf , but the "books" objects that I think only the block of < strong> MainWindow as is logical,

If someone could help me with the logic of initialization in WPF or give me a reference of a website that could help me, thank you very much in advance and sorry if I have something wrong in the newsroom.

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();
    }
    
asked by HOLDTHEDOOR 03.07.2018 в 21:15
source

1 answer

1

HODOR, as it goes. I recommend that you follow the official documentation of Microsoft.- link something in Spanish. On the other hand, from console to wpf I find something abrupt, you could research windows forms with which you will be able to take several concepts to wpf.

Regarding your question 1) Class the instances when you need it: >

and with the 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;
//Asigna el valor cuando se inicialicen los elementos de window
 InitializeComponent();
        label1.Content= Libro0.Autor; //exception nullreference

    }
    
answered by 03.07.2018 / 22:12
source