c# - How to call an event from other page Windows Phone? -
i making upload app windows phone, function in class b (secondpage), have upload task, when task completed, call event , notice class (mainpage) task done , things, looking around site, found solutions don't (just think that).
here code in secondpage
public sealed partial class secondpage : page { public event eventhandler clearhandler = delegate { }; public secondpage() { this.initializecomponent(); } protected override void onnavigatedto(navigationeventargs e) { } private void btnclear_tapped(object sender, tappedroutedeventargs e) { //some works if (clearhandler != null) clearhandler(this, null); } }
in mainclass
public sealed partial class mainpage : page { public mainpage() { this.initializecomponent(); this.navigationcachemode = navigationcachemode.required; } protected override void onnavigatedto(navigationeventargs e) { secondpage sp = new secondpage(); sp.clearhandler += sp_clearhandler; } private void sp_clearhandler(object sender, eventargs e) { txt.text = ""; } private void btnjump_tapped(object sender, tappedroutedeventargs e) { frame.navigate(typeof(secondpage)); } }
the textbox named txt not cleared, can guys please me, thank you!
you can use observablecollection notify 1 page another. public static observablecollection<string> yesnostatus { get; internal set; }
where want notify thn
yesnostatus = new observablecollection<string>(); yesnostatus.collectionchanged += yesnostatus_collectionchanged;
and event method like:-
private void yesnostatus_collectionchanged(object sender, notifycollectionchangedeventargs e) { observablecollection<string> obssender = sender observablecollection<string>; }
add in collection after operation completed ..thn notify.
Comments
Post a Comment