WPF整理-跨程式集訪問資源
阿新 • • 發佈:2018-12-27
“Sometimes binary resources are defined in one assembly (typically a class library), but are
needed in another assembly (another class library or an executable). WPF provides a uniform
and consistent way of accessing these resources using the pack URI scheme.”
假如我們定義一個WPF User Control Library,並在其中新增一張圖片,設定其屬性為Resource。
現在我們新建一個WPF Application,然後新增這個Library的引用。
則我們可以這樣訪問Library中的Resource,Code Snip如下:
<Image Source="/ClassLibraryResources;component/Images/6.png" />
在C#中,如下訪問:
image1.Source = new BitmapImage(new Uri("/ClassLibraryResources;component/Images/6.png",UriKind.Relative));
程式執行如下: