C# WPF桌面程序分層結構設計

不使用MEF等依賴注入技術的架構設計

  • Views,按功能劃分組織用戶控件文件
  • Business,業務邏輯
  • DAL,數據庫ORM中間層
  • Infrastructure,基礎架構工具
  • Log facility
  • Json Helper classes
  • Design Pattern Helper classes
  • Basic Converters

關于Resource Dictionary

Resource dictionaries are usually defined in the App.xaml. 不過根據[Ref-2]的方式,我們在架構中希望將資源定義在獨立的模塊中,然后從其他模塊引用它。與[Ref-2]不一樣的是,我們將資源統一包含在Shell項目的App.xaml中,所以我們還需要解決設計期資源字典訪問問題。

why views can consume app.xaml even if they’re defined on a separate project

[Ref-1].

Resources defined in the App.xaml become available in the Application.Resources ResourceDictionary of the current Application class (which can be accessed through the Application.Current static property.) Once they’re available there, they can be consumed from within the XAML as static resources. Since modules are loaded into the same application domain as the Shell project, views defined there can access resources as long as they can be found in the corresponding Application.Resources dictionary.

在模塊中定義資源,在其他模塊(Shell)中訪問

[Ref-2]中是任意的UserControl中自定義資源引用,我們需要在Shell中統一引用資源,則在Shell的App.xaml中添加如下代碼:
<pre><ResourceDictionary Source="pack://application:,,,/TradeStation.Infrastructure;component/Resources/Generic.xaml"></ResourceDictionary></pre>
值得注意的是,[Ref-2]說使用“Generic.xaml”作為名字有“huge benifits”,這個好像

設計期資源引用

在Shell的App.xaml中統一定義資源字典的一個問題是,VS在設計期無法正確的處理。
[Ref-3]涉及到了這個問題,但是好像沒有太簡單、一次性的解決方案。最終的解決方案還是在每一個UserControl中的Resources中添加與App.xaml中一樣的一行:
<pre><ResourceDictionary Source="pack://application:,,,/TradeStation.Infrastructure;component/Resources/Generic.xaml"></ResourceDictionary></pre>

題外話:define resource dictionaries that are specific to a certain module

[Ref-1]

參考資料

[1]《How to: define module-specific resource dictionaries in Prism》介紹了利用模塊中的app.xaml來實現
[2] https://stackoverflow.com/a/8594334/351993
[3] How to use resource dictionary in prism modules at design time?

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 8,925評論 0 6
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,973評論 19 139
  • 帶上面具的他,處事冷靜、沉著、內斂、穩重;容不得別人的背叛,對背叛自己的人,絕不原諒,對敵人下手狠毒,冷血至極……...
    gjamdt閱讀 228評論 0 0
  • 本文為大地瓜原創,歡迎知識共享,轉載請注明出處。雖然你不注明出處我也沒什么精力和你計較。作者微信號:christg...
    大地瓜123閱讀 190評論 0 0
  • 我是誰?這個問題不乏被思考過,偶然苦惱一會兒,卻得不出一個完美的答案,于是被我拋諸腦后,不常再被我記起。我想我是與...
    東東嘿小妖閱讀 276評論 0 2