Home > DeveloperSection > Forums > How to set a default value on a DataTemplate?
ezra heywood
ezra heywood

Total Post:145

Posted on    August-16-2013 5:54 AM


 1 Reply(s)
 988  View(s)
Rate this:
Hi Mindstick!

Can you see this tag: 

<Image Source="{Binding Image}" Stretch="UniformToFill"/> 

But below? What I'm trying to do is, when the Image is null, set another default image. Is this possible? 

<!-- Grid-appropriate 250 pixel square item template as seen in the GroupedItemsPage and ItemsPage -->

<DataTemplate x:Key="Standard250x250ItemTemplate">

    <Grid HorizontalAlignment="Left" Width="320" Height="240">

        <Border Background="{StaticResource ListViewItemPlaceholderRectBrush}">

            <Image Source="{Binding Image}" Stretch="UniformToFill"/>


        <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundBrush}">

            <TextBlock Text="{Binding ShortTitle}" Foreground="{StaticResource ListViewItemOverlayTextBrush}" Style="{StaticResource TitleTextStyle}" Height="48" Margin="15,0,15,0"/>




Thanks in advance

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    August-17-2013 7:05 AM


Add a Style with a DataTrigger. e.g. something like

<Image Stretch="UniformToFill">


         <Style TargetType="Image">

             <Setter Property="Source" Value="{Binding Image}"/>


                 <DataTrigger Binding="{Binding Image}" Value="{x:Null}">

                     <Setter Property="Source" Value="Images/Default.png"/>







Don't want to miss updates? Please click the below button!

Follow MindStick