微軟企業庫5.0學習筆記(八)windows表單和WPF應用

來源:互聯網
上載者:User

雖然他們是不同的技術,但是他們具有相同的基本特徵。特別是他們都使用表單對象來實現使用者介面,並且都允許你指定應用程式啟動時啟動並執行代碼。預設情況下,啟動代碼只是載入並顯示主表單,但是你可以修改它來建立一個統一的容器,用企業庫資訊組裝它,並處理應用中使用的對象。例如,為了減少啟動時間和使用記憶體,你可能不希望在啟動是建立所有表單。你可以儲存一個容器的對象來處理表單和其他需要的對象。

Windows表單應用程式

下面顯示怎麼在windows表單中建立並組裝企業庫容器

static void Main()<br />{<br /> var container = new UnityContainer()<br /> .AddNewExtension<EnterpriseLibraryCoreExtension>();<br /> Application.Run(container.Resolve<Form1>());<br />}<br />

 

WPF應用程式

Wpf應用程式使用啟動代碼載入並顯示主表單。

當建立一個WPF工程時, Visual Studio建立一個應用程式定義檔案.使用C#的話, 它被命名App.xaml 並有一個關聯的代碼檔案App.xaml.cs.

Xml檔案內容

<Application x:Class="Window1"<br /> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br /> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br /> Startup="CreateContainer"><br /> <Application.Resources></p><p> </Application.Resources><br /></Application><br />

 

Cs檔案內容

private void CreateContainer(object sender, StartupEventArgs e)<br />{<br /> var container = new UnityContainer()<br /> .AddNewExtension<EnterpriseLibraryCoreExtension>();<br /> Window1 theWindow = container.Resolve<Window1>();<br /> theWindow.Show();<br />}<br />

 

 

相關文章

聯繫我們

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