C # Windows Store App, Windows Phone App development, so that the upper layer of the parent container UserControl calling method (Method).

Generally, we in the development of Windows Store App, or Windows Phone App, uses modular UserControl to each paging function, making the parent container can call methods within the UserControl, but how can we make the call to the parent container UserControl way for UserControl and parent container be able to pass on, be able to call each other's way to do that?!

This article will guide you to make the top of the parent container UserControl call method (method).


Generally, we in the development of Windows Store App, or Windows Phone App, uses modular UserControl to each paging function, making the parent container can call methods within the UserControl, but how can we make the call to the parent container UserControl way for UserControl and parent container be able to pass on, be able to call each other's methods?!

This article will guide you to make method calls UserControl top of the parent container (Method).

Recap :

C # Windows Store App, Windows Phone App development, use UserControl development App, each page features a modular, easy to manage.

On top of this link which indicates that we can through the [parent container] call [method] of UserControl.

This article is to teach the method through [UserControl] call [] of the parent container.

First, let's establish a UserControl] [] is called [MyUserControl

image

And will produce two files MyUserControl.xaml and MyUserControl.xaml.cs when new UserControl

MyUserControl.xaml while the former is used to configure UI user interface, no longer the focus of Benpian years,

Benpian focus is on how the program should be presented in the narrative,

Of course, after reading this article you can through the UI (buttons and the like) to call on one [parent container] method,

Incoming layer of [] in the parent container initialization program,

Assume [set] for the parent container MainPage, which is the default open new projects coming in the main page,

Also a new method (Method) to be used to call the method with the parent container,

   1:  public partial class MyUserControl : UserControl
   2:  {
   3: // used to store one Mainpage keep the same memory location
   4:      private MainPage mianpage;
   5:      public MyUserControl(MainPage _mainpage)
   6:      {
   7:          InitializeComponent();
   8: // mainpage configure their class and its parent container object with the same memory location of
   9:          mianpage = _mainpage;
  10: // initialization is complete we can call the method of the parent container
  11: mianpage.CallFromUserControl ();
  12:      }
  13:  }

Then MainPage program to add new MyUserControl MyUserControl call and ready to use methods of CallFromUserControl

   1:  private void initialUserControl() {
   2: // add a MyUserControl and to pass itself in, is this
   3:      MyUserControl myUsercontrol = new MyUserControl(this);
   4:   
   5: // add to the Stage
   6:      LayoutRoot.Children.Add(myUsercontrol);
   7:   
   8:   
   9:   
  10:   
  11:  }
  12: // must be written public disclosure methods in order to call on MyUserControl
  13:  public void CallFromUserControl()
  14:  {
  15: MessageBox.Show ( "This is called from a UserControl");
  16:  }

So long as the call within the UserControl mianpage.CallFromUserControl (); parent can be called the upper container [La] method !!

Thus [parent container] and [UserControl] was associated together !! let each other be able to pass on.

References: SUKI realize out of their own

The article describes the concept, if not correct the wrong section, welcome to inform correct me thank you
please indicate the source, and attach this article URL! Thanks.

SUKI

HOLIESTAR

https://www.facebook.com/Holiestar
https://www.facebook.com/firestar.register

Original: Large column  C # Windows Store App, Windows Phone App development, so that the upper layer of the parent container UserControl calling method (Method).


Guess you like

Origin www.cnblogs.com/chinatrump/p/11458292.html