dotnet / dotnet/wpf

The bitmap image associated with the ToolboxBitmap property does not appear in the toolbox.

Open
#10,178 5 comments 0 reactions 0 assignees View on GitHub
External Non-WPF Issue
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

When creating a custom control, if you use the ToolboxBitmap property, the bitmap image associated with this attribute does not appear in the toolbox.
For the program test, the bitmap image is included in a folder.
I also tested with the image included in a resource file.
The problem remains the same.

The same test with a winforms project works perfectly.

Here is the code
'----------------------------------
Imports System.Drawing
Imports System.Windows.Controls.Primitives

****
Public Class CustomControl1
Inherits System.Windows.Controls.Control

Shared Sub New()
'Cet appel OverrideMetadata indique au système que cet élément souhaite apporter un style différent de celui de sa classe de base.
'Ce style est défini dans themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(GetType(CustomControl1), New FrameworkPropertyMetadata(GetType(CustomControl1)))
End Sub

End Class
'---------------------------

Here is the image of the ToolboxBitmap attribute.

![Image](https://github.com/user-attachments/assets/329cb59d-ce1f-42b6-b954-83379547326c)

You see the image not present in the toolbox.

![Image](https://github.com/user-attachments/assets/4a4e9002-6a5a-407b-a272-fa8705e085e6)

With the same project in winforms, the image is visible.

`---------------------------------------
****
Public Class CustomControl1

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)

'Ajoutez ici votre code de dessin personnalisé
End Sub

End Class
`--------------------------------------

![Image](https://github.com/user-attachments/assets/fd3eecf4-5a6c-4de2-8f66-4fe400c1e8d5)

### Reproduction Steps

Create a project with a custom control.
Added the ToolboxBitmap attribute whose value is a path to a bitmap file to the custom control.
Build the project.

### Expected behavior

View of the ToolboxBitmap attribute image in the toolbar.

### Actual behavior

No view of ToolboxBitmap attribute image in toolbar.

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

Visual studio 2022 Version 17.12.1
.Net 9
Project in VB.

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.