Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Binding images to an ImageButton at runtime

Binding images to an ImageButton at runtime

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfhardwarehelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wolfram Steinke
    wrote on last edited by
    #1

    I'm finally getting a chance to work with WPF. Making a Button with an Image on it is no problem as long as I don't mind embedding the image in the resource. What can't get working is to have it load the image from file in a subfolder under the Application at runtime. I don't want it in the embedded resources. Any ideas? It must be possible to do.

    Happy programming!!

    P 1 Reply Last reply
    0
    • W Wolfram Steinke

      I'm finally getting a chance to work with WPF. Making a Button with an Image on it is no problem as long as I don't mind embedding the image in the resource. What can't get working is to have it load the image from file in a subfolder under the Application at runtime. I don't want it in the embedded resources. Any ideas? It must be possible to do.

      Happy programming!!

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      An easy way to do this is to specify a Uri to the image as in the following code:

      myImage.BeginInit();
      myImage.Source = new BitmapImage(new Uri(file));
      myImage.EndInit();

      Obviously, you'll have to pass the fully qualified file name into the Uri, but this code will work.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      W 1 Reply Last reply
      0
      • P Pete OHanlon

        An easy way to do this is to specify a Uri to the image as in the following code:

        myImage.BeginInit();
        myImage.Source = new BitmapImage(new Uri(file));
        myImage.EndInit();

        Obviously, you'll have to pass the fully qualified file name into the Uri, but this code will work.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        W Offline
        W Offline
        Wolfram Steinke
        wrote on last edited by
        #3

        How does one go about putting it on the button? It must be possible but documentation on this topic worse than ever and impossible to find.

        Happy programming!!

        C P 2 Replies Last reply
        0
        • W Wolfram Steinke

          How does one go about putting it on the button? It must be possible but documentation on this topic worse than ever and impossible to find.

          Happy programming!!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          There same property you set in XAML, you can set in code.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • W Wolfram Steinke

            How does one go about putting it on the button? It must be possible but documentation on this topic worse than ever and impossible to find.

            Happy programming!!

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            It's not that hard to do, and there are plenty of samples on the web. Your XAML looks like this:

            <Button>
            <Image x:Name="myImage" />
            </Button>

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            W 1 Reply Last reply
            0
            • P Pete OHanlon

              It's not that hard to do, and there are plenty of samples on the web. Your XAML looks like this:

              <Button>
              <Image x:Name="myImage" />
              </Button>

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              W Offline
              W Offline
              Wolfram Steinke
              wrote on last edited by
              #6

              Thanks for your assistance. There are heaps of examples that load images from embedded resources for sure. So far I have found only one that half works the way I need it to work.

              Happy programming!!

              P 1 Reply Last reply
              0
              • W Wolfram Steinke

                Thanks for your assistance. There are heaps of examples that load images from embedded resources for sure. So far I have found only one that half works the way I need it to work.

                Happy programming!!

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                I'm glad I could help then.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups