My Silverlight系列(13)—— Silverlight Windows

來源:互聯網
上載者:User
眾所周知,在微軟的Windows平台,我們有許許多多的案頭應用,這讓我們的生活變得豐富多彩而且有趣。在BS結構應用和RIA應用大行其道的今天,有很多案頭版應用推出了ajax版本和flex版本,免安裝的同時也讓升級和維護變得更加容易了。
Silverlight作為RIA的一種,它的優勢體現在豐富的互動性上。如果說案頭版應用的載體是Windows Explorer的話,那麼Silverlight應用的載體就是Internet Explorer(用FF的同學不要罵我,我還是喜歡IE的,因為它對SL的支援更好一些)。過去的一段時間,我通過補充和修改一些SL2時代寫的代碼,把Explorer這個概念搬到了Silverlight上,以求摸擬WPF上Window這個類的特性。由於本人的美術功底不好沒有藝術細胞,而且也不怎麼會用Blend,所以做出來的UI實在是有點不太好看。不過至少基本的功能都實現得差不多了,在這裡我簡要地介紹一下。
對於這個項目,主要的功能幾乎全部由Explorer和Form這兩個Control實現,前者可以定製WallPaper, Desktop Shortcuts, TaskBar等等,並且對所有的Form對象進行統一管理;後者主要用以支援最大化、還原、最小化,拖拽,改變視窗大小和視窗位置等邏輯功能。運行時的效果大約(這個是我自己的山寨版MSN):

Explorer類與Form類的使用也相對簡單,Explorer只需要寫在Xaml裡面,一般使其成為Application.Current.RootVisual的根項目,使其能夠充滿整個Silverlight應用即可。Form類大約可以像Silverlight3中推出的ChildWindow一樣使用,只不過在Show之前需要設定它的Explorer屬性,不然的話會出現null 指標。

在這個基礎上實現一個自己的Form很簡單,由於Form本身是一個ContentControl,那麼在Xaml中可以這樣定義:<provider:Form x:Class="SilverlightWindow.HelloWorld"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:provider="clr-namespace:WinFormProvider.Controls;assembly=WinFormProvider"
    Width="600" Height="400" Icon="icon.jpg" Title="Hello World" Top="100" Left="100"
    ShowInTaskBar="True" MinWidth="500" MinHeight="300">
    <provider:Form.TrayAreaIcon>
        <provider:TrayAreaIcon Icon="icon.jpg" DoubleClick="TrayAreaIcon_DoubleClick"/>    
    </provider:Form.TrayAreaIcon>
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock>
            Hello, there is a form, it will show with 100px XOffset and 100px YOffset
            <LineBreak/>
            You can resize it, and drag it, or close it
            <LineBreak/>
            I don't konw how to create an introduction documentation
            <LineBreak/>
            However, I think this control is quite easy, you can do it as WPF window
            <LineBreak/>   
            <LineBreak/>
            <LineBreak/>
            And don't be surprised if the footer disappers from taskbar when you minimize the form
            <LineBreak/>
            it is because I think if there is a trayarea icon, footer is useless
        </TextBlock>
    </Grid>
</provider:Form>

而且背景代碼中,由於開放了比較豐富的public、protected屬性、方法以及事件,因此我們可以實現很多功能,具體您可以參考代碼以及樣本。

這個項目(包括樣本)我已經將它發布到了codeplex上面:http://silverlightwindow.codeplex.com/,是一個Alpha版本。如果哪位有興趣的話,可以聯絡我,大家一起把它完善了。
我仔細閱讀了有關把文章放到首頁的要求,感覺我這篇隨筆像是屬於4) 軟體發布的文章,但是我希望能有更多的人看到這篇文章,如果您喜歡silverlight,覺得這個項目有價值的話,歡迎加入我,大家一起豐富和完善這個項目。
最後再小小慶祝一下本人在silverlight官網(http://silverlight.net/forums)的積分達到2000,成功晉級contributor。留念:
  

相關文章

聯繫我們

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