使用silverlight構建一個工作流程設計工具(十二)

來源:互聯網
上載者:User

原始碼下載:http://www.shareidea.net/opensource.htm

線上示範:http://www.shareidea.net/workflow.htm

視頻教程: http://www.shareidea.net/video/sharedesigner/sharedesigner.html

本章包含以下內容:

l 新的活動圖表形,圖形更加清晰漂亮.

l 增加對上下左右鍵的支援(選中活動或者規則後,使用方向鍵進行移動,按住Ctrl時,每次移動的距離加大).不過有一個問題,無法捕獲方向鍵的按下事件,卻能捕獲鬆開滑鼠事件,不知為何

l 實現我們第十章講到的變化皮膚的方法。

本章上面的兩點更新沒有什麼值的要說的,下面實現我們在第十章講的變幻皮膚的方法,

如果您還不瞭解變幻皮膚的原理,請參考第十章的內容。

八、實現更換皮膚功能

我們對Activity.Xaml類來做實驗,步驟如下:

1.首先我們把Activity.g.cs(位於obj"Debug"Designer檔案夾下)中的類變數和InitializeComponent方法拷貝的Activity.xaml.cs檔案中。這些代碼如下所示:

internal System.Windows.Controls.Canvas container;
internal System.Windows.Controls.ToolTip ttActivityTip;
internal System.Windows.Shapes.Ellipse eiCenterEllipse;
internal Shareidea.Web.UI.Control.Workflow.Designer.ActivityPictureContainer sdPicture;
private bool _contentLoaded;
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent()
{
if (_contentLoaded)
{
return;
}
_contentLoaded = true;
System.Windows.Application.LoadComponent(this, new System.Uri("/ShareDesigner;component/Designer/Activity.xaml", System.UriKind.Relative));
this.container = ((System.Windows.Controls.Canvas)(this.FindName("container")));
this.ttActivityTip = ((System.Windows.Controls.ToolTip)(this.FindName("ttActivityTip")));
this.eiCenterEllipse = ((System.Windows.Shapes.Ellipse)(this.FindName("eiCenterEllipse")));
this.sdPicture = ((Shareidea.Web.UI.Control.Workflow.Designer.ActivityPictureContainer)(this.FindName("sdPicture")));
}

2.然後編譯代碼,這時候會發生錯誤,說已經存在了相同的變數和方法。這是因為在Activity.xaml.cs和Activity.g.cs檔案中存在了相同的代碼。我們把Activity.g.cs內容全部刪除,再次編譯,ok,通過了。

3.雖然編譯通過了,但是InitializeComponent代碼卻無法設定斷點,原因是設定了屬性

[System.Diagnostics.DebuggerNonUserCodeAttribute()]

這個屬性用以表示標識不屬於應用程式使用者代碼的類型或成員,這個屬性告訴vs.net調試機制不會進入這一段代碼。我們把這個屬性注釋掉,然後再運行就可以了。

4.接下來建立一個新的activity皮膚檔案。通過vs.net類瀏覽器,我們拷貝Activity.xaml檔案,並且拷貝的新檔案命名為Activity2.xaml.

5.然後編譯代碼,發生錯誤,因為自動產生的Activity2.g.cs檔案中包含了一些代碼,我們把Activity2.g.cs清空,然後再編譯。Ok,通過。

6.修改一下Activity2.xaml的樣式,以區別於Activity.xaml。

7.修改Activity.xaml.cs檔案中的 System.Windows.Application.LoadComponent(this, new System.Uri("/ShareDesigner;component/Designer/Activity.xaml", System.UriKind.Relative))方法,把/Activity.xaml修改為/Activity2.xaml,使得載入新的皮膚Activity2.xaml檔案。

最後運行代碼,可以看到,使用新的Activity2.xaml檔案了。

這樣我們就可以通過改變System.Windows.Application.LoadComponent的第二個參數來動態載入指定的皮膚。

到此為止,我們已經完成了一個變幻皮膚的代碼。不過還有一些可以深入思考的地方。

1、如果有很多皮膚,那麼不希望使用者在第一次載入的時候就下載所有的皮膚檔案,這樣會增加使用者等待時間,如果能動態從網路上下載xmal代碼就好了,不過還沒有找到這個方法。

2、上面的方法並沒有使得.xmal和xaml.cs檔案失去關聯,我們可以手工剪下xaml.cs檔案到其它檔案吧,而把皮膚檔案(.xmal檔案)放在單獨的檔案夾中,便於管理。

3、自動產生的.g.cs檔案能不能去掉呢?這個檔案是在編譯時間候自動產生的,位於obj"Debug"Designer檔案夾下。

聯繫我們

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