Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For myself, I created the following example:</p> <pre><code>&lt;!-- xmlns:sys="clr-namespace:System;assembly=mscorlib" --&gt; &lt;Window.Resources&gt; &lt;!-- Test data --&gt; &lt;local:TestDataForImage x:Key="MyTestData" /&gt; &lt;!-- Image for FallbackValue --&gt; &lt;sys:String x:Key="ErrorImage"&gt;pack://application:,,,/NotFound.png&lt;/sys:String&gt; &lt;!-- Image for NULL value --&gt; &lt;sys:String x:Key="NullImage"&gt;pack://application:,,,/NullImage.png&lt;/sys:String&gt; &lt;/Window.Resources&gt; &lt;!-- Grid using DataContext --&gt; &lt;Grid DataContext="{StaticResource MyTestData}"&gt; &lt;Image Name="ImageNull" Width="100" Height="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="{Binding Path=NullString, TargetNullValue={StaticResource NullImage}}" /&gt; &lt;Image Name="ImageNotFound" Width="100" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Path=NotFoundString, FallbackValue={StaticResource ErrorImage}}" /&gt; &lt;/Grid&gt; </code></pre> <p>The path to the images, I announced in resources. Images are stored in the root of the project. Listing of <code>MyTestData</code>:</p> <pre><code>public class TestDataForImage : DependencyObject { public string NotFoundString { get { return (string)GetValue(NotFoundStringProperty); } set { SetValue(NotFoundStringProperty, value); } } public static readonly DependencyProperty NotFoundStringProperty = DependencyProperty.Register("NotFoundString", typeof(string), typeof(TestDataForImage), new PropertyMetadata("")); public string NullString { get { return (string)GetValue(NullStringProperty); } set { SetValue(NullStringProperty, value); } } public static readonly DependencyProperty NullStringProperty = DependencyProperty.Register("NullString", typeof(string), typeof(TestDataForImage), new PropertyMetadata("")); public TestDataForImage() { NotFoundString = "pack://application:,,,/NotExistingImage.png"; NullString = null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload