Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 185393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:27:42+00:00 2026-05-11T15:27:42+00:00

I need to dynamically change the background image applied to one of my buttons,

  • 0

I need to dynamically change the background image applied to one of my buttons, but can’t figure out how. The images are added to the project and have their Build Action set to Resource. I’ve tried the follow:

buttonUnits.Background = new ImageBrush(new BitmapImage(new Uri('/Images/InchDOWN.png',UriKind.Relative))); 

This compiles successfully, but will crash with a DirectoryNotFoundException saying ‘Could not find a part of the path ‘C:\Images\InchDOWN.png’.’

I don’t want the app to look for the image on disk. How can I use the image as an embedded resource? I would think it involves changing the Build Action to Embedded Resource, but how do I use this resource in the code behind?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:27:43+00:00Added an answer on May 11, 2026 at 3:27 pm

    You have to build the image as a Resource NOT an embedded resource. Resource is there specifically to be used by WPF projects.

    To use it in procedural code:

     buttonUnits.Background = new ImageBrush(new BitmapImage(new Uri('pack://application:,,,/Images/InchDOWN.png'))); 

    This is a lot easier to do in XAML which I recommend.

    Edit

    I forgot a forward slash before Images, that could be the problem. Here is a MSDN article about pack Uris if you need more info.

    Maybe you should post a question stating what exactly you’re trying to accomplish and hopefully discover different approaches to your multi-state button problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change background of the activity dynamically , by selecting an image
My project is in PHP, I need change the image folder name in css
I've got a litte js script which can change background images. You can address
Is it possible to have vector shapes and dynamically change the background image by
I need to change the background colour of specific list items in a dynamically
I need to change ASPxGridView SettingsLoadingPanel dynamically (from code behind if is possible). For
I need to dynamically create textbox. This is my code, but with this I
I need to dynamically load banner images into a HTML5 app and would like
I need to dynamically insert an image in my JS code. In my Razor
I am trying to change JList rows dynamically. I need change nth row colour,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.