c# - How to update a ListView with a Button click in different pages? -




i've 2 different xaml pages, in first 1 i've button , in other page listview. i've done binding stuff , create "model" class.
listview:

<listview x:name="listaeventos" itemssource="{x:bind eventos}" fontfamily="segoe ui emoji">                 <listview.itemtemplate>                     <datatemplate x:datatype="data:evento">                         <stackpanel orientation="horizontal">                             <textblock text="{x:bind minuto}" style="{themeresource captiontextblockstyle}" verticalalignment="center"/>                             <textblock text="{x:bind segundo}" style="{themeresource captiontextblockstyle}" verticalalignment="center"/>                             <textblock text="{x:bind icono}" margin="10,0,0,0" verticalalignment="center"/>                             <textblock text="{x:bind accion}" margin="10,0,0,0" verticalalignment="center"/>                             <textblock text="{x:bind equipo}" verticalalignment="center"/>                         </stackpanel>                     </datatemplate>                 </listview.itemtemplate>             </listview> 

and model class:

public class evento {     public string minuto { get; set; }      public string segundo { get; set; }      public string icono { get; set; }      public string accion { get; set; }      public string equipo { get; set; }  } 

finally, i've button in other page , want add item, this:

eventos.add(new evento { minuto = "10", segundo = "00", icono = "👌", accion="triple de", equipo=" visitante" }); 

i've done lot of research haven't found useful information or similar simple. please upvote, need help, thanks!

we can define static observablecollection add new item in other page. can not bind listview static observablecollection can override onnavigatedto event , set static observablecollection eventos.

for example:

public static  observablecollection<evento> staticevento; public  observablecollection<evento> eventos { get; set; } public mainpage() {     this.initializecomponent();     if (staticevento == null)     {         staticevento = new observablecollection<evento>();         staticevento.add(new evento { minuto = "20", segundo = "00", icono = "👌", accion = "triple de", equipo = " visitante" });         eventos = staticevento;     } } protected override void onnavigatedto(navigationeventargs e) {     eventos = staticevento; } 

another page:

private void button_click(object sender, routedeventargs e) {     mainpage.staticevento.add(new evento { minuto = "10", segundo = "00", icono = "👌", accion = "triple de", equipo = " visitante" });     frame rootframe = window.current.content frame;     rootframe.goback(); } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -