locked
Dynamically change picture in itemTemplate RRS feed

  • Question

  • Hi

    I have a data grid that users the below ItemTemplate. How do I change the picture displayed dynamically based on a bound value?

    What I am tying to do is change a picture for an item dependent on the bound value.. I do not want to switch ItemTeplate

    Change this

     <Image Grid.Column="1" HorizontalAlignment="Right" Height="67" Margin="0,-45,0,0" VerticalAlignment="Top" Width="59" Source="Assets/5.png"/>

    to

     <Image Grid.Column="1" HorizontalAlignment="Right" Height="67" Margin="0,-45,0,0" VerticalAlignment="Top" Width="59" Source="Assets/NewPic.png"/>

    when isPro is true

      <TextBlock Text="{Binding isPro}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="10,20,0,10"/>

      <DataTemplate x:Key="CustomTileItem">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="59*"/>
                    <ColumnDefinition Width="51*"/>
                    <ColumnDefinition Width="7*"/>
                    <ColumnDefinition Width="69*"/>
                </Grid.ColumnDefinitions>
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Grid.ColumnSpan="4" Margin="0,0,-0.001,0">
    
                    <Image Source="{Binding Thumbnail}" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
    
    
                </Border>
    
                <StackPanel VerticalAlignment="Top" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}" Orientation="Horizontal" Grid.ColumnSpan="4" Margin="0,0,-0.001,0">
    
                    <TextBlock Text="{Binding MyName}" Style="{StaticResource TitleTextStyle}" Height="24" Margin="15,0,15,0" RenderTransformOrigin="0.523,1.75" Foreground="White" FontSize="14" FontWeight="ExtraBold"/>
                    <Image Grid.Column="1" HorizontalAlignment="Right" Height="67" Margin="0,-45,0,0" VerticalAlignment="Top" Width="59" Source="Assets/5.png"/>
    
    
    
                </StackPanel>
    
                <StackPanel VerticalAlignment="Bottom"  HorizontalAlignment="Right" Grid.Column="3" Margin="0,0,-0.001,0">
                 
    
                    <TextBlock Text="{Binding Promise}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="0,0,10,10" FontSize="25" FontWeight="ExtraBold"  HorizontalAlignment="Right" Foreground="#FF12D3F1" VerticalAlignment="Bottom" />
                </StackPanel>
    
                <StackPanel VerticalAlignment="Bottom" Grid.ColumnSpan="4" Margin="0,0,0,0" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                    <TextBlock Text="{Binding Title}"     Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}"  Margin="10,0,0,0" HorizontalAlignment="Left" FontSize="12"/>
                    <TextBlock Text="{Binding Locations}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}"  Margin="10,0,0,10" HorizontalAlignment="Left" FontSize="12" />
                    <TextBlock Text="{Binding StartDate}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="10,0,0,10"/>
                    <TextBlock Text="{Binding isPro}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="10,20,0,10"/>
    
    
    
                </StackPanel>
            </Grid>
        </DataTemplate>
    
        
        





    • Edited by Andy Sid Sunday, November 17, 2013 9:27 PM
    Sunday, November 17, 2013 8:45 PM

Answers

All replies