accessing image files from a separated assembly

2019-06-05 16:34发布

问题:

I have several image files I want to share between projects(common icons) I have them in an assembly that would be in every solution I create...I have the files in a folder called Icon and I have the build as content copy always. I have verified that a folder is created with these icons...however my other assemblies are not able to find them...

<r:RibbonGroup Header="Users">
    <r:RibbonButton >
       <r:RibbonButton.LargeImageSource>
            <BitmapImage UriSource="..\Icons\UserIcon.png" />
       </r:RibbonButton.LargeImageSource>
    </r:RibbonButton>
</r:RibbonGroup>

i have tried formatting the uri several ways...but it never succeeds. If the icons are in the actual assembly though they work...

回答1:

Try using an absolute Uri. Build action must be set to Resource for UserIcon.png

<BitmapImage UriSource="pack://application:,,,/NameOfImageAssembly;component/Icons/UserIcon.png"/>

Relative Uri should also work

<BitmapImage UriSource="/NameOfImageAssembly;component/Icons/UserIcon.png"/>