Data binding and images
Hello everybody!
I'm using the December CTP, and I'm trying to create an image that's bound to some XML in an XmlDataProvider, thus:
<
StackPanelOrientation="Vertical"><ImageWidth="48"Height="48">
<Image.Source>
<BitmapImageUriSource="{Binding XPath=Image}" />
</Image.Source>
</Image>
<TextBlockText="{Binding XPath=Name}"/>
</StackPanel>
I'm setting the data context programmatically to an XmlDataProvider defined in C#, into which I stuff some XML. This works fine for the textblock, but not for the image - I get the following exception:
{"Error at element 'BitmapImage' in markup file 'browserbuttons.xaml' : Property 'UriSource' or property 'StreamSource' must be set.."}
If I put the URI from the XML into the XAML, it works fine.
Any ideas?
The exception only gets raised at runtime. The code builds fine.
Incidentally, if I use a converter class to convert the string to a bitmap image and bind to the source attribute on the image in the XAML it works fine, thus:
<
Image Grid.Column="1" Grid.Row="1" Source="{Binding XPath=Image, Converter={StaticResource buttonImageConverter}}" /> public class ButtonImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new BitmapImage(new Uri(value.ToString(), UriKind.RelativeOrAbsolute));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
So it's not a showstopper or anything.