Skip to content

Conversation

@magsonleone
Copy link

@magsonleone magsonleone commented Sep 12, 2025

Summary of the Pull Request

What is this about:
Add in-memory image support and contextual help to RibbonExtensions

Description:

This PR introduces new features and improvements to the Ribbon extensions for Revit:

  • New in-memory image support
    • Added SetImage(Bitmap) and SetLargeImage(Bitmap) methods to apply 16x16 and 32x32 icons directly from System.Drawing.Bitmap.
    • Automatic conversion to WPF BitmapSource, enabling runtime or embedded resource icons.
  • Simplified contextual help
    • Added SetContextualHelp(string url) method to quickly associate documentation or support pages with Ribbon buttons.
  • Technical updates
    • Added System.Drawing.Common dependency to the project.
    • Introduced ConvertToImageSource() helper for safe and efficient GDI+ to WPF conversion.

These additions make Revit UI customization more flexible and dynamic, supporting both runtime-generated icons and integrated online help.

Quality Checklist

  • [ x ] My code follows the style guidelines of this project
  • [ x ] I have performed a self-review of my own code
  • [ x ] My changes generate no new warnings

Introduced a new method `SetContextualHelp` for the `RibbonItem` class, enabling the assignment of contextual help via a URL. Comprehensive XML documentation has been added to clarify its purpose, parameters, return value, and provide usage examples.
This commit introduces several using directives for WPF and image handling namespaces, enabling the use of WPF features in the Ribbon UI. A new private static method, `ConvertToImageSource`, is added to the `RibbonExtensions` class to convert `System.Drawing.Bitmap` to a WPF `ImageSource`, suitable for button icons. XML documentation comments are included for clarity. The existing code structure remains unchanged.
Implemented two new methods, `SetImage` and `SetLargeImage`, for the `RibbonExtensions` class. These methods enable setting images for Ribbon buttons using in-memory `System.Drawing.Bitmap` objects. Comprehensive XML documentation has been added for both methods, detailing their purpose, parameters, return values, remarks, and usage examples.
Updated `Nice3point.Revit.Extensions.csproj` to include
a new package reference for `System.Drawing.Common`
version `8.0.8` in the `<ItemGroup>` section.
Eliminated the `using System.Windows.Media.Imaging;` directive
to clean up unused namespaces and avoid potential conflicts
in the context of Revit 2024 or greater.
Clarified that the method converts a System.Drawing.Bitmap to a WPF-compatible BitmapSource. Updated parameter and return type descriptions, and added remarks about unmanaged HBITMAP handling. Changed the method signature to return BitmapSource instead of ImageSource for better specificity.
@magsonleone
Copy link
Author

Hi @Nice3point, could you take a look at this pull request?

@Nice3point
Copy link
Owner

I see you are trying to add support for .resx files. Bitmap, .resx and EmbeddedResource are specific to WinForms, not WPF. WinForms is too outdated a technology and adding support for it makes no sense. Use WPF and Resource + pack:// URI

@magsonleone
Copy link
Author

Hi @Nice3point, could you take a look at this pull request?

Thanks, @Nice3point .

Quick clarification:

  • This PR does not add .resx support or WinForms assets. It adds two overloads that accept System.Drawing.Bitmap and converts them to WPF BitmapSource. The existing WPF-first APIs (SetImage(string uri), SetLargeImage(string uri)) remain and already support pack:// URIs.
  • System.Drawing.Bitmap isn’t WinForms-specific; it’s GDI+ and can be used in WPF after conversion. .resx/EmbeddedResource are .NET mechanisms in general and are not introduced here.

Intent: enable scenarios where icons are produced at runtime or come from streams/embedded data and are already available as Bitmap, while keeping the WPF pack:// path fully supported.

@Nice3point
Copy link
Owner

Give me an example with a Bitmap and where BitmapImage is not enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants