Setting FormatConvertedBitmap Source via Binding

by admin 29. December 2005 00:53

Avalon's FormatConvertedBitmap is a convenient way of getting a greyscale version of an image, but it appears to have some trouble with setting the source property via data binding. The following code fails complaining that the Source property has not been set on the FormatConvertedBitmap:

<Image Grid.Column="0" Grid.Row="1" Width="400" Height="200">
<FormatConvertedBitmap Source="{Binding Path=ImageSource,
Converter={StaticResource imageFormatConverter}}" DestinationFormat="Gray32" />

I've tested the databinding on a standard image and it is fine. Similarly the code works correctly if a uri is entered instead of the binding expression.

I've no idea why this is happening, but I have managed to find a work around by using a converter to set the outer image's source instead of embedded XAML. e.g.

<Image Grid.Column="1" Grid.Row="1" Source="{Binding Path=ImageSource, 
Converter={StaticResource imageFormatConverter},
ConverterParameter=Gray32}" />

public class FormatConverter : IValueConverter
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
BitmapSource source = new BitmapImage(new Uri(value.ToString()));
return new FormatConvertedBitmap(source,
(PixelFormat)new PixelFormatConverter().ConvertFrom(parameter), null, 0);

public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
throw new Exception("The method or operation is not implemented.");

I suppose I should fire this at the newsgroup and see if I can find more insight into what's happening.

Comments are closed

About Us

RikWare is a software development company based in Brisbane, Australia. Led by director, Richard Mason, RikWare focusses on solving challenging business problems promptly and effectively.

RikWare is also the owner of Aussie Bushwalking, a free, wiki-like collaboration site for bushwalkers and the creator of RikMigrations, a migration framework for .NET.

Aussie Bushwalking

Want to discover some new bushwalking ideas? Share a few of your own? Aussie Bushwalking is like Wikipedia... but for bushwalkers. Head on over. Anybody can see the walks and it's free to sign up and share your own.



RikMigrations is a database migration library for .NET based on the migrations facility provided by Ruby on Rails. It allows simple upgrading and downgrading of databases using .NET code (such as VB or C#) either from the command line or built into your application. Unlike many other migration frameworks, RikMigrations is a stand-alone library which does not rely on a large surrounding framework.