Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you guessed correctly, templates and triggers are indeed your friend here.</p> <p>Here is an implementation using the <code>ContentControl</code>:</p> <pre><code>&lt;ContentControl Content="{Binding Path=UserAvatar}"&gt; &lt;ContentControl.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;Image x:Name="image" Source="{Binding}"/&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding}" Value="{x:Null}"&gt; &lt;Setter TargetName="image" Property="Source" Value="--your awesome default image here--" /&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.ContentTemplate&gt; &lt;/ContentControl&gt; </code></pre> <p>And in the situation when your default thingy is no <code>ImageSource</code>, and you wish to play around a bit with other controls, you can always resort to the <code>Visibilty</code> property:</p> <pre><code>&lt;ContentControl Content="{Binding Path=UserAvatar}"&gt; &lt;ContentControl.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Image x:Name="image" Source="{Binding}" /&gt; &lt;Canvas x:Name="defaultImage" Visibility="Collapsed" /&gt; &lt;/Grid&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding}" Value="{x:Null}"&gt; &lt;Setter TargetName="image" Property="Visibility" Value="Collapsed" /&gt; &lt;Setter TargetName="defaultImage" Property="Visibility" Value="Visible" /&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.ContentTemplate&gt; &lt;/ContentControl&gt; </code></pre> <p>Hope this helps..</p>
 

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