WPF整理-跨程序集訪問資源

「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.」ide

假如咱們定義一個WPF User Control Library,並在其中添加一張圖片,設置其屬性爲Resource。spa

 

如今咱們新建一個WPF Application,而後添加這個Library的引用。code

則咱們能夠這樣訪問Library中的Resource,Code Snip以下:component

<Image  Source="/ClassLibraryResources;component/Images/6.png" />

在C#中,以下訪問:orm

image1.Source = new BitmapImage(new Uri("/ClassLibraryResources;component/Images/6.png",UriKind.Relative));

程序運行以下:
blog

相關文章
相關標籤/搜索