App.xaml用途是什麼?怎麼傳遞參數和使用?

來源:互聯網
上載者:User

Silverlight裡面有個App.xaml和App.xaml.cs,是幹什麼的,用途是什麼,怎麼和它傳遞參數呢?

使用它裡面的public參數很簡單,假設在MainPage.xaml.cs你可以這樣訪問:

(Application.Current as App).YourPublicParam

同樣,在Silverlight Class Library類庫項目中你也可以用上面的方法訪問App裡面的變數,因為Application.Current是application全域的。

App.xaml來源

App.xaml和App.xaml.cs存在於Silverlight和WPF項目中,它來源於System.Windows.Application類庫,如果熟悉Winform開發的就應該對這個東西比較熟悉。當Silverlight Application啟動的時候,順序是這樣的:

  • 沒有 Main() 方法
  • 啟動 App 構造器
    • Application_Startup 事件handler綁定到App.Startup屬性
    • Application_Exit 事件handler綁定到App.Exit 屬性
    • Application_UnhandledException事件handler綁定到UnhandledException 屬性
    • 觸發InitializeComponent
  • Application_Startup
    • 建立新的 Page 對象執行個體
    • App.RootVisual 指向這個Page對象
  • InitializeComponent
    • 調用Application.LoadComponent, 傳遞Uri 對象到 App.xaml

    App.xaml用途

  • 定義全域資源:我們可以把Application層級的資源放在這裡,用Application.Resources屬性訪問,常用的有styles, data templates,control templates。
  • 全域事件處理:Startup, Exit 和UnhandledException.
  • 全域引用Application.Current
  • 指定RootVisible: RootVisual 用來設定Silverlight啟動控制項,這個屬性在 Startup 事件中設定.
  • 本地安裝application:使用Install 方法你可以讓使用者在瀏覽器外本地安裝application
  • 檢查更新:本地安裝的時候可以用CheckAndDownloadUpdateAsync 方法檢查.xap檔案是否最新
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.