Wednesday 15 January 2014

c# - add data item to observablecollection? -


I need to add selected items to this collection. I choose my item on one item and then the app show and I want to use the app button to add the item that was used to add the object that will be displayed on the second page.

  Private Zero Button Button (object) Sender, Tapped Event Event e) {AllActors m = new AllActors (); Actor objkt = itemGridView.SelectedItem; M.allActors.Add (objkt); }   

This does not work ... here are my classes:

  public class AllActors: LivingDataCommon {public AllActors (): base (string. Epty, String.Empty) {} Public AllActors (String ID, String Title): Base (ID, Title) {} Private Observe Collection & lt; ActorsObject & gt; _AllActors = New Inspection Qualification & lt; ActorsObject & gt; (); Public Supervision Collection & lt; ActorObject & gt; AllActors {Get {this return.AllActors; }}}      

Problem one: Compiler error "implicitly type"

  ActorsObject objkt = itemGridView.SelectedItem;   

Gridview's chosen item property returns an object returning you are trying to assign it to a variable type of ActorsObject type, and the compiler does not assume it's okay. You have to tell ...

  ActorsObject objkt = (ActorsObject) itemGridView.SelectedItem;   

In the compiler's error message specifically asked "Do you remember an artist?" And told this line that this is useful information - it has just told you what was wrong and suggested how to fix it. Always read compiler errors and think about what they are saying, do not underestimate it "does not work".


Issue two: "This does not do what I want"
  Private zero button buttonpayment (Object Sender, Tapered Event ARG E) {AllActors m = New AllActors (); Actor objkt = itemGridView.SelectedItem; M.allActors.Add (objkt); }   

Read this carefully and think what it is doing. On the first line of the function, you are creating a new AllActors object and assign it to 'm' On the third row, you make changes to that object. But then your task is finished, and you have thrown that object!

It is more likely that in order to achieve what you want, you need to create an All Actors object as a field on your window class. Then you can place the object around, bind it, and any change will be made for it. Something like that, though you will also need some UI to display this data.

  Private AllActors _m = new AllActors (); Private Zero Button_Tapped_1 (Object Sender, Tapped Event ARG E) {ActorsObject objkt = (ActorsObject) itemGridView.SelectedItem; _m.allActors.Add (objkt); }    

No comments:

Post a Comment