Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 106565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:37:00+00:00 2026-05-11T01:37:00+00:00

I have a grid laid out like so; +———+———+ | Image | Details |

  • 0

I have a grid laid out like so;

+---------+---------+ |  Image  | Details | |    is   |  pane   | |  here   | for data| |         |  entry  | +---------+---------+ | ListView here to  | | select data item  | | for top two panes | +---------+---------+ 

This all works well, but I would now like to change the image to another set of controls saying ‘Sorry, no image available’ when the selected item in the listview does not have an image

I’ve tried wrapping the image in a DockPanel and setting a DataTemplate there (so I can use DataTriggers) but IntelliSense says no!

The ListView uses DataTriggers to do a similar thing, but as I say I can’t get my head round how to do it for a single image that does not seem to have access to a DataTemplate.

Simplified XAML is below;

<Grid DataContext='{Binding Source={StaticResource MyData}}'>    <!-- row 0 col 0 -->    <Image x:Name='imgPhoto' Source='{Binding ElementName=MyListViewOfData, Path=SelectedItem.PathToImageOnDisk}' />     <!-- row 0 col 1 -->    <StackPanel DataContext='{Binding ElementName=MyListViewOfData, Path=SelectedItem}'>       <TextBox Name='NameTextBox' Text='{Binding Name}' />       <TextBlock Name='DateCreatedTextBlock' Text='{Binding DateCreated}' />    </StackPanel>     <!-- row 1 cols 0,1 -->    <ListView ItemsSource='{Binding}' ItemTemplate='{StaticResource MyListViewTemplate}'  IsSynchronizedWithCurrentItem='True' Name='MyListViewOfData' />  </Grid> 

Thanks in advance WPF gurus.

Ryan

Update: Both answers below (Abe and Jobi) were spot on, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:37:01+00:00Added an answer on May 11, 2026 at 1:37 am

    In order to use a DataTemplate, you have to have a control that uses the template to render an object. If you use a ContentPresenter, you can set its ContentTemplate to be a DataTemplate to whatever you like.

    Here is how I would do this:

    <Grid DataContext='...'>     <ContentPresenter Content='{Binding SelectedItem, ElementName=MyListViewOfData}'>         <ContentPresenter.ContentTemplate>             <DataTemplate>                 <Grid>                     <Grid.ColumnDefinitions>                         <ColumnDefinition />                         <ColumnDefinition />                           </Grid.ColumnDefinitions>                     <Image x:Name='imgPhoto' Source='{Binding PathToImageOnDisk}' />                     <TextBlock x:Name='error' Visibility='Collapsed' Text='Sorry, no image available' />                     <StackPanel Grid.Column='1'>                         <TextBox Name='NameTextBox' Text='{Binding Name}' />                         <TextBlock Name='DateCreatedTextBlock' Text='{Binding DateCreated}' />                     </StackPanel>                 </Grid>             <DataTemplate.Triggers>                 <DataTrigger Binding='{Binding PathToImageOnDisk}' Value='{x:Null}'>                     <Setter TargetName='imgPhoto' Property='Visibility' Value='Collapsed' />                     <Setter TargetName='error' Property='Visibility' Value='Visible' />                 </DataTrigger>             </DataTemplate.Triggers>             </DataTemplate>         </ContentPresenter.ContentTemplate>     </ContentPresenter>     <ListView ItemsSource='{Binding}' ItemTemplate='{StaticResource MyListViewTemplate}' IsSynchronizedWithCurrentItem='True' Name='MyListViewOfData' />  </Grid> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The alternative to the imp module that (I believe) should… May 13, 2026 at 1:35 pm
  • Editorial Team
    Editorial Team added an answer A bit further down the same page: "The role attributes… May 13, 2026 at 1:35 pm
  • Editorial Team
    Editorial Team added an answer Yes; you can write your own main method and run… May 13, 2026 at 1:35 pm

Related Questions

I have a grid laid out like so; +---------+---------+ | Image | Details |
I have a graph with four nodes, each node represents a position and they
So I have a StackPanel that I am using as a ContentControl. I have
I have a grid of items which is populated using databinding. In the grid
I have a grid with several thousand rows that can be filtered and sorted.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.