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?

[3611 byte] By [FrancisTracey] at [2008-2-7]
# 1
Is something that only happens at design time or does it happen at runtime as well?
MarkBoulter at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,WPF Designer (Cider)...
# 2

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.

FrancisTracey at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,WPF Designer (Cider)...
# 3

Fran,

unfortunately you've hit the limit of my Avalon knowledge. Since this is a runtime issue rather than a Cider issue I'd suggest trying the WPF forum - http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&SiteID=1

mark

MarkBoulter at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,WPF Designer (Cider)...

Visual Studio Orcas

Site Classified