Converting byte[] to ImageSource in PropertyEditor

Grids for WPF Forum

Posted 1 year ago by Procam
Version: 19.1.0683


I have a class with property Thumbnail of type Byte[]. An instance of this class is set as DataObject for PropertyGrid.

In the PropertyEditor for the PropertyGrid I have:

<grids:PropertyEditor PropertyName="Thumbnail">
                    <Grid Background="White" Height="75">
                        <Image Source="{Binding Value, Converter={StaticResource ByteToImageSourceConverter}, UpdateSourceTrigger=PropertyChanged}" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"></Image>

where the ByteToImageSourceConverter returns:

BitmapSource bitmap = (BitmapSource)new ImageSourceConverter().ConvertFrom(bytes);
return bitmap;

The result in the Property grid is that apart of the Image, there are also below the image the bytes enumerated as [0], [1], etc.

Hot to get rid of these "byte" items in property grid?

Comments (3)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA


Yes that is the correct way to make a custom property editor to show the Image.  

The other issue you mentioned is because you have a byte array, our data factory is defaulting to making the property expandable so you can see the items.  I believe if you put this attribute on the property, it will prevent that:


Actipro Software Support

Posted 1 year ago by Procam

Thanks for your quick reply. I added the TypeConverter (as below) but have still the expanded [0],[1],... items.

private Byte[] thumbnail;
[Category("Graphic"), DisplayName("Thumbnail"), Display(Order = 99)]
public Byte[] Thumbnail
    get => thumbnail;
    set => SetProperty(ref thumbnail, value);

Or maybe need I a special converter?

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA

Hmm, when we added that generic TypeConverter to our own test, it seemed to work since it would prevent the default ArrayConverter from being used.  ArrayConverter overrides the GetProperties and GetPropertiesSupported methods to return child properties, which are the items.  You could try making your own TypeConverter that returns false from GetPropertiesSupported and see if that helps.

Other than that, the other way would be to inherit our default data factory class and make one of your own.  Then override its methods to filter out child properties when properties that return byte arrays.

Actipro Software Support

The latest build of this product (v2020.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.