Search code examples
wpfxamldesign-timeexpression-blend-4blendability

How to display Image with design-time Source in Expression Blend


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).


Solution

  • 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}}"/>