In pageA I have a HyperlinkButton link that links to pageB
private void Link1_Click_1(object sender, RoutedEventArgs e) { HyperlinkButton btn = sender as HyperlinkButton; string url = btn.Tag.ToString(); this.mainFrame.Navigate(new Uri(url, UriKind.Relative)); }
How can I make a COMPLEX object on pageA accessible to pageB?
Either pass it when I recreate pageB or make it a public property on page A, which I can access, I think?
I could add an object in App.xaml so that it is accessible everywhere, but I don't think the best rating
I think the easiest way is to use a global context implementation to set / receive your data.
public class Context { static Context _context = null; static object sync = new object(); public object Data { get; set; } private Context() { } public static Context GetContext() { if _context == null) { lock (sync) { if _context == null) { _context = new Context(); } } } return _context; } } //Load your data, and on any page you need it, just do: Context c = Context.GetContext(); //set or get c.Data here
, /
, , () . , , , , , , . , , Initialize (StatusObject status), , . PageB. - Navigated , , NavigationEventArgs.Content. , , , ...
Session .
E.g.:- Page A: MyComplexObject complex = new MyComplexObject(); Session["cObj"] = complex; Page B: if(Session["cObj"] != null){ MyComplexObject new_complex = (MyComplexObject)Session["cObj"]; } or MyComplexObject new_complex = Session["cObj"] as MyComplexObject;
, , - DataContext PageA, pageB
((System.Windows.Controls.Frame)this.Parent).DataContext
silverlight , , , asp.net. , - , .
public class Cache { private static Cache _cache; private Cache() {} public Cache Instance { get { if(_cache == null) _cache = new Cache(); return _cache; } } public object CachedData {get; set;} }
Cache.Instance.CachedData = () "Hello World"; string Data = () Cache.Instance.CachedData;
, , .
Script dependent, but isolated storage can be considered an option. It is designed to store data on the client side to reduce server load, and this is apparently the perfect scenario based on what you described.
Source: https://habr.com/ru/post/1728139/More articles:What is wrong with this eval statement in Perl? - evalDoes Android launch OpenGL ES 1.1 or 1.0? - androidWhy specify an explicit database connection? - phpHow to use an entity structure at the business level and / or data level? - c #Почему этап undefined в моем классе ActionScript 3, хотя я импортировал класс Stage? - actionscript-3https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1728140/aspnet-passing-arguments-to-the-server-on-button-click&usg=ALkJrhi8Zgoiq-ykxJzpx7royC_lDyb__gBoost Library for RTTI - c ++CSS IE6 float right - htmlHow to change FxCop language? - internationalizationwhy in this case the compiler does not complain? - c #All Articles