silverlight 父表單傳值給ChildWindow

來源:互聯網
上載者:User

標籤:style   blog   class   c   code   java   

在網上找了許多列子,有的沒有看懂,有的太麻煩。

現在有兩種方法又簡單又實用的,分享給大家!

第一種:使用建構函式傳值

1、子頁面建立一個建構函式

1  public ChildWindowTest(string TextS)2         {3           4             InitializeComponent();5             //父類傳過來的值6             this.Text1.Text = TextS;7         }8 9 //TextS就是父頁面傳過來的值

2、父頁面建立子頁面的對象

1 //需要在ChildWindow中建構函式進行傳值2 ChildWindowTest ChildWindow = new ChildWindowTest("ChildWindow用法:父頁,子頁相互傳值");

3、子頁面的建構函式的參數 TextS 就是“ChildWindow用法:父頁,子頁相互傳值”

第二種:

1、在子頁面定義一個方法

1 public void UpdateText(string Str) 2         {3             tbName.Text = Str;4         }

2、在父頁面建立子頁面對象

1 ChildWindowTest ChildWindow = new ChildWindowTest();

3、在父頁面對開子頁面時,調用子頁面的方法:

1 ChildWindow.UpdateText("ChildWindow用法:父頁,子頁相互傳值");

子頁面的方法UpdateText(string Str)中,就可以操作這個傳過來的值了。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.