Search code examples
c#flowdocument

Setting source to resource image inside project


I samples of FlowDocument in C# show images pointing to a location on disk in the xaml file. If I want to point source to image inside program as resource or how do i set the source setting then? I ship my program flowdocument as part of the program and I cant install images on disk. I want them as resource inside the program.

  <InlineUIContainer >
      <Image Margin="2,0" Width="50" Source="C:\sample.jpg" ></Image>
  </InlineUIContainer>

Solution

  • You should set image's Build action to Resource and use following code:

        <InlineUIContainer >
            <Image Margin="2,0" Width="50" Source="pack://application:,,,/YourAssemblyName;Images/sample.jpg"></Image>
        </InlineUIContainer>
    

    sample.jpg must be in folder "Images" in your project in this example.