Resource URI in WPF UserControl, which is hosted in Windows Forms application












0















I have a WPF UserControl, which is using some PNG bitmap resources as part of it's UI. Currently, those files are referenced with Build Action: Content and a Copy to Output Directory: Do not copy. Elements on this UserControl are using following URI to access the resource:
pack://application:,,,Resources/ui/Cross.png which works fine in designer.



The user control is then used in a Windows Forms application through ElementHost control at which point all image links stop working. The UserControl is in it's own assembly and Windows Forms application is referencing that assembly.



I have also tried changing the URI to this: pack://application:,,,Assembly.Name;component/Resources/ui/Cross.png



I have further tried reading this to no help.



The only option I have left is to include code to manually set ImageSource of all Image elements on the user control, which would require a lot of work. I feel like there must be a way to resolve this better.










share|improve this question





























    0















    I have a WPF UserControl, which is using some PNG bitmap resources as part of it's UI. Currently, those files are referenced with Build Action: Content and a Copy to Output Directory: Do not copy. Elements on this UserControl are using following URI to access the resource:
    pack://application:,,,Resources/ui/Cross.png which works fine in designer.



    The user control is then used in a Windows Forms application through ElementHost control at which point all image links stop working. The UserControl is in it's own assembly and Windows Forms application is referencing that assembly.



    I have also tried changing the URI to this: pack://application:,,,Assembly.Name;component/Resources/ui/Cross.png



    I have further tried reading this to no help.



    The only option I have left is to include code to manually set ImageSource of all Image elements on the user control, which would require a lot of work. I feel like there must be a way to resolve this better.










    share|improve this question



























      0












      0








      0








      I have a WPF UserControl, which is using some PNG bitmap resources as part of it's UI. Currently, those files are referenced with Build Action: Content and a Copy to Output Directory: Do not copy. Elements on this UserControl are using following URI to access the resource:
      pack://application:,,,Resources/ui/Cross.png which works fine in designer.



      The user control is then used in a Windows Forms application through ElementHost control at which point all image links stop working. The UserControl is in it's own assembly and Windows Forms application is referencing that assembly.



      I have also tried changing the URI to this: pack://application:,,,Assembly.Name;component/Resources/ui/Cross.png



      I have further tried reading this to no help.



      The only option I have left is to include code to manually set ImageSource of all Image elements on the user control, which would require a lot of work. I feel like there must be a way to resolve this better.










      share|improve this question
















      I have a WPF UserControl, which is using some PNG bitmap resources as part of it's UI. Currently, those files are referenced with Build Action: Content and a Copy to Output Directory: Do not copy. Elements on this UserControl are using following URI to access the resource:
      pack://application:,,,Resources/ui/Cross.png which works fine in designer.



      The user control is then used in a Windows Forms application through ElementHost control at which point all image links stop working. The UserControl is in it's own assembly and Windows Forms application is referencing that assembly.



      I have also tried changing the URI to this: pack://application:,,,Assembly.Name;component/Resources/ui/Cross.png



      I have further tried reading this to no help.



      The only option I have left is to include code to manually set ImageSource of all Image elements on the user control, which would require a lot of work. I feel like there must be a way to resolve this better.







      wpf xaml wpf-controls windowsformsintegration






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 11:50







      masiton

















      asked Nov 21 '18 at 10:27









      masitonmasiton

      357




      357
























          1 Answer
          1






          active

          oldest

          votes


















          1















          Build Action: Content and a Copy to Output Directory: Do not copy




          That combination does not work. Content requires that the file is copied.



          However, you should use Build Action Resource. And your Pack URI misses a slash after ,,,.



          It should be



          pack://application:,,,/AssemblyName;component/Resources/ui/Cross.png


          provided that the image file is part of your Visual Studio Project, located in a subfolder named ui in a project folder named Resources.



          See Resource File Pack URIs for details.






          share|improve this answer


























          • The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

            – masiton
            Nov 21 '18 at 11:02











          • Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

            – Clemens
            Nov 21 '18 at 11:04













          • I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

            – masiton
            Nov 21 '18 at 11:07











          • Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

            – Clemens
            Nov 21 '18 at 11:25













          • Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

            – Clemens
            Nov 21 '18 at 11:33













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410012%2fresource-uri-in-wpf-usercontrol-which-is-hosted-in-windows-forms-application%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          Build Action: Content and a Copy to Output Directory: Do not copy




          That combination does not work. Content requires that the file is copied.



          However, you should use Build Action Resource. And your Pack URI misses a slash after ,,,.



          It should be



          pack://application:,,,/AssemblyName;component/Resources/ui/Cross.png


          provided that the image file is part of your Visual Studio Project, located in a subfolder named ui in a project folder named Resources.



          See Resource File Pack URIs for details.






          share|improve this answer


























          • The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

            – masiton
            Nov 21 '18 at 11:02











          • Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

            – Clemens
            Nov 21 '18 at 11:04













          • I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

            – masiton
            Nov 21 '18 at 11:07











          • Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

            – Clemens
            Nov 21 '18 at 11:25













          • Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

            – Clemens
            Nov 21 '18 at 11:33


















          1















          Build Action: Content and a Copy to Output Directory: Do not copy




          That combination does not work. Content requires that the file is copied.



          However, you should use Build Action Resource. And your Pack URI misses a slash after ,,,.



          It should be



          pack://application:,,,/AssemblyName;component/Resources/ui/Cross.png


          provided that the image file is part of your Visual Studio Project, located in a subfolder named ui in a project folder named Resources.



          See Resource File Pack URIs for details.






          share|improve this answer


























          • The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

            – masiton
            Nov 21 '18 at 11:02











          • Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

            – Clemens
            Nov 21 '18 at 11:04













          • I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

            – masiton
            Nov 21 '18 at 11:07











          • Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

            – Clemens
            Nov 21 '18 at 11:25













          • Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

            – Clemens
            Nov 21 '18 at 11:33
















          1












          1








          1








          Build Action: Content and a Copy to Output Directory: Do not copy




          That combination does not work. Content requires that the file is copied.



          However, you should use Build Action Resource. And your Pack URI misses a slash after ,,,.



          It should be



          pack://application:,,,/AssemblyName;component/Resources/ui/Cross.png


          provided that the image file is part of your Visual Studio Project, located in a subfolder named ui in a project folder named Resources.



          See Resource File Pack URIs for details.






          share|improve this answer
















          Build Action: Content and a Copy to Output Directory: Do not copy




          That combination does not work. Content requires that the file is copied.



          However, you should use Build Action Resource. And your Pack URI misses a slash after ,,,.



          It should be



          pack://application:,,,/AssemblyName;component/Resources/ui/Cross.png


          provided that the image file is part of your Visual Studio Project, located in a subfolder named ui in a project folder named Resources.



          See Resource File Pack URIs for details.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 11:32

























          answered Nov 21 '18 at 10:32









          ClemensClemens

          89.3k890182




          89.3k890182













          • The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

            – masiton
            Nov 21 '18 at 11:02











          • Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

            – Clemens
            Nov 21 '18 at 11:04













          • I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

            – masiton
            Nov 21 '18 at 11:07











          • Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

            – Clemens
            Nov 21 '18 at 11:25













          • Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

            – Clemens
            Nov 21 '18 at 11:33





















          • The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

            – masiton
            Nov 21 '18 at 11:02











          • Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

            – Clemens
            Nov 21 '18 at 11:04













          • I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

            – masiton
            Nov 21 '18 at 11:07











          • Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

            – Clemens
            Nov 21 '18 at 11:25













          • Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

            – Clemens
            Nov 21 '18 at 11:33



















          The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

          – masiton
          Nov 21 '18 at 11:02





          The mentioned has no effect on whether the images load or not. It is a known issue with hosted controls, I'm looking for an advise how to resolve this. No combination of build action and uri formatting will resolve this.

          – masiton
          Nov 21 '18 at 11:02













          Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

          – Clemens
          Nov 21 '18 at 11:04







          Not sure what you are trying to say, but Content and Do not copy will definitely not work together. Use Build Action Resource and a Referenced Assembly Resource File Pack URI.

          – Clemens
          Nov 21 '18 at 11:04















          I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

          – masiton
          Nov 21 '18 at 11:07





          I'm trying to say that your proposed changes do not resolve the situation either. You can't just play around with build action and tune the URI link and expect that a WPF control hosted in Windows Forms app will suddenly work and URI resource links will suddenly spring to life. That entire feature doesn't work in hosted environment as explained by Dr. WPF in the link provided in the question.

          – masiton
          Nov 21 '18 at 11:07













          Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

          – Clemens
          Nov 21 '18 at 11:25







          Just tried it, and it works perfectly. Hosted a WPF UserControl in an ElementHost in a WinForms app. UserControl has an Image element with a BitmapImage loaded from a full Pack URI. You are not supposed to "play around" with Build Action and other resource file settings. Just set them correctly. Also make sure your resource file path is correct, i.e. there is a folder "Resources" with a subfolder "ui".

          – Clemens
          Nov 21 '18 at 11:25















          Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

          – Clemens
          Nov 21 '18 at 11:33







          Also double check that you used the correct assembly name in the Pack URI. Do not use a namespace name.

          – Clemens
          Nov 21 '18 at 11:33






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410012%2fresource-uri-in-wpf-usercontrol-which-is-hosted-in-windows-forms-application%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()