Home>

In the XAML window, I have a TextBlock, which should output data using binding. But he does not see what should output. Tell me, please, how to fix?

<
TextBlock grid.row= "0" grid.column= "0" text= "Subscription:" fontweight= "bold" fontsize= "12" foreground= "White" />
            ≪
TextBlock grid.row= "0" grid.column= "1" text= "{binding itemmodel.name}" fontweight= "bold" fontsize= "12" foreground= "white" />
                            ≪
TextBlock grid.row= "1" grid.column= "0" text= "Price:" fontweight= "bold" fontsize= "12" foreground= "white" />
            ≪
TextBlock grid.row= "1" grid.column= "1" text= "{binding itemmodel.price, stringformat= {} {0} rub}" fontweight= "bold" fontsize= "12" foreground= "white" /≫
                            ≪
TextBlock grid.row= "2" grid.column= "0" text= "Subscription time:" fontweight= "bold" fontsize= "12" foreground= "white" />
            ≪
TextBlock grid.row= "2" grid.column= "1" text= "{binding itemmodel.time, stringformat= {} {0} month}" fontweight= "bold" fontsize= "12" foreground= "white" /≫
                            ≪
TextBlock grid.row= "3" grid.column= "0" text= "Subject:" fontweight= "bold" fontsize= "12" foreground= "White" />
            ≪
TextBlock grid.row= "3" grid.column= "1" text= "{binding itemmodel.topic}" fontweight= "bold" fontsize= "12" foreground= "white" />
                            ≪
TextBlock grid.row= "4" grid.column= "0" text= "Author:" fontweight= "bold" fontsize= "12" foreground= "White" />
            ≪
TextBlock grid.row= "4" grid.column= "1" text= "{binding itemmodel.author}" fontweight= "bold" fontsize= "12" foreground= "white" />

ItemModel takes everything from the database.

Public int ID {Get; SET; }
        Private String Name, Topic, Author;
        Private int Price, Time;
        Public String Name.
        {
            get {Return Name; }
            set {name= value; }
        }
        Public int Price
        {
            get {Return Price; }
            SET {Price= Value; }
        }
        Public Int Time.
        {
            Get {Return Time; }
            set {Time= Value; }
        }
        Public String Topic
        {
            get {Return Topic; }
            set {Topic= Value; }
        }
        Public String Author
        {
            get {Return Author; }
            set {author= value; }
        }
        Public ItemModel () {}
        Public ItemModel (String Name, Int Price, Int Time, String Topic, String Author)
        {
            this.name= Name;
            this.price=;
            this.Time= Time;
            this.topic= Topic;
            this.author= author;
        }

Not enough information to understand what is the problem. DataContext set? Why do your model perform the role of the look-model? If the data changes after creating an instance of the model, then you need to implement InotifyPropertyChanged to see the interface to see these changes. If the data do not change, then why are setters implemented in properties?

aepot2021-06-09 10:54:11

Yes, the data is changing, I have adding and deleting subscriptions. Also datactext is implemented. It turns out to be implemented inotifyPropertyChanged to work?

Dr. Crow2021-06-09 11:24:15

What is presented in DataContext? Is there a public property in the class with the ItemModel type and the same name (Alya Public ItemModel ItemModel {Get;})?

EvgeniyZ2021-06-09 11:30:12

Why do you have this all static? Statua is not a place in the project! Well, also look carefully on your code, I repeat the question "Do you have a public property with the ItemModel type in the SamplePost and a similar name?" I do not see this, I see that SamplePost is ItemModel, then why does the binding go so itemmodel.name, and not so Name?

EvgeniyZ2021-06-09 11:39:21

Everything has earned! After Itemmodel removed, it became an XDG0008 error, I poked on it and found a solution, namely, deleting the .vs folder and rebuild. Now everything is displayed, thanks for the help! Now it remains adding to do correctly so that not only sample has shown, but also what has added.

Dr. Crow2021-06-09 11:48:28