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

  • Home
  • SEARCH
  • 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 359727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:25:16+00:00 2026-05-12T12:25:16+00:00

I have a WPF application and I added to the project resources many icons

  • 0

I have a WPF application and I added to the project resources many icons and bitmaps.

Now I can access them like this:

Dim ico As System.Drawing.Icon = My.Resources.Icon 'Icon.ico
Dim img As System.Drawing.Bitmap = My.Resources.Image 'Image.png

In order to use it in wpf I created too simple Extension Methods that convert them to ImageSource type:

'...Imports System.Drawing
'...Imports System.Windows.Interop.Imaging
<Extension()> _
Public Function ToImageSource(ByVal icon As Icon) As BitmapSource
    Return CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, _
        BitmapSizeOptions.FromEmptyOptions)
End Function

<Extension()> _
Public Function ToImageSource(ByVal image As Bitmap) As BitmapSource
    Return CreateBitmapSourceFromHBitmap(image.GetHbitmap(), IntPtr.Zero, _
        Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions)
End Function

So I can use it this way:

Dim i As New Image With {.Source = My.Resources.Image.ToImageSource}

Taking a look at MyWpfExtensions.vb reveals me that there are few Microsoft infrastractures that allow unofficial coding and here comes my question to the experts of you.

I’d like to have for each resource of type System.Drawing.Bitmap/Icon an additional (or overriding) property that returns the image via the ex. method so I don’t have to use a converter in the Xaml, but use it directly.

I am actually looking for something like Microsoft.VisualBasic.MyGroupCollectionAttribute.

Any ideas?…

  • 1 1 Answer
  • 1 View
  • 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. Editorial Team
    Editorial Team
    2026-05-12T12:25:16+00:00Added an answer on May 12, 2026 at 12:25 pm

    I guess there is not other way but a converter so let’s post it:

    Imports System.Drawing
    Namespace Converters
        <ValueConversion(GetType(MarshalByRefObject), GetType(BitmapSource))> _
        Public Class ImageSourceConverter : Implements IValueConverter
            Public Function Convert(value As Object, targetType As Type, 
            parameter As Object,
            culture As System.Globalization.CultureInfo) As Object
            Implements System.Windows.Data.IValueConverter.Convert
                Dim imageSource As ImageSource = Nothing
                Dim type = value.GetType
                If type.Equals(GetType(Icon)) Then
                    imageSource = DirectCast(value, Icon).ToImageSource
                ElseIf type.Equals(GetType(Bitmap)) Then
                    imageSource = DirectCast(value, Bitmap).ToImageSource
                End If
    
                Return imageSource
            End Function
    
            Public Function ConvertBack(value As Object, targetType As Type,
            parameter As Object,
            culture As System.Globalization.CultureInfo) As Object Implements
            System.Windows.Data.IValueConverter.ConvertBack
                Throw New NotSupportedException
            End Function
        End Class
    End Namespace
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images added to Properties.Resources , where I can access them like:
I have a WPF application where I added the images as resources to the
Is there a way to search a WPF application for resources? I have added
i have a WPF Application with a LoginWindow to access,so i create a Splash
I have a WPF application with several windows. I would like to define GLOBAL
I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused
I have seen this thread: WPF image resources and applied the information there. But
I've added WindowsMediaPlayer ActiveX to my WPF/MVVM application. Now I need the control to
I have WPF Application where I have One main form and other user controls
I have WPF C# application that communicate with a PLC (i.e. write/read Omron PLC's

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.