5

I have an Image down some controls in a XAML visual tree. I would like to display a design-time image, so that I can check layout, dimensions, etc. Something equivalent to this:

<UserControl.Resources>
    <Something x:Key="DesignSource" Uri="/Image/sourceimage.png"/>
</UserControl.Resources>

<Image
    Source="{Binding RealSource}"
    d:Source="{StaticResource DesignSource}"/>

Where "something" would be some imagesource provider pointing to some image file, and "d:Source" is here just to show my intent: to define different sources at the same time: one for runtime, other for design time.

Usage of DataProviders in XAML or SampleData (Blend) are welcome (I know they exist, but don't know how to include images).

heltonbiker
  • 26,657
  • 28
  • 137
  • 252

1 Answers1

10

You could achieve that by setting the Binding's FallbackValue:

<UserControl.Resources>
    <BitmapImage x:Key="DesignSource" UriSource="/Image/sourceimage.png"/>
</UserControl.Resources>

<Image Source="{Binding RealSource, FallbackValue={StaticResource DesignSource}}"/>
Clemens
  • 123,504
  • 12
  • 155
  • 268