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

  • SEARCH
  • Home
  • 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
  • 2 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

Related Questions

I have grid with some textboxes and an image which goes out of grid
I have a large table of data roughly laid out as follows. As requested
I have grid something like this: Ext.define('Exp.view.dashboard.Tv', { extend: 'Ext.grid.Panel', initComponent: function() { this.columns
I have grid of images, when the mouse is over any given image a
i have data-grid in my application and i want to customize my data-grid so
I have a grid which I would like to show extra information with RowExpander
I have an instance of AQGridView laid out in a Pages-esque manner for the
I have grid with user data with first column having check box. I have
I have grid, where I have a lot of records. There is operation like
Hai presently i have grid like this. <Grid Name=tGrid1 Grid.Row=0 Background=Black > </Grid> <Grid

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.