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 3959280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:42:40+00:00 2026-05-20T02:42:40+00:00

I have a listbox that I’m doing some databinding. As you can see I

  • 0

I have a listbox that I’m doing some databinding. As you can see I have some images associated with the data that I’m displaying… Everything is working great, except that when I change themes I need to change my image to the black images. I can’t seem to figure out how to change the images when they are bound like this.

Any ideas?

            <ListBox x:Name="lbPharm" ItemsSource="{Binding col}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                            <TextBlock FontFamily="Segoe WP Semibold" FontWeight="Bold" FontSize="30" VerticalAlignment="Top" Margin="20,10">*</TextBlock>
                            <StackPanel>
                                <TextBlock x:Name="ItemText" Text="{Binding name}"  FontSize="{StaticResource PhoneFontSizeLarge}"/>
                                <TextBlock x:Name="ItemNumber" Text="{Binding number}"  FontSize="{StaticResource PhoneFontSizeNormal}"/>
                            </StackPanel>

                            <Image Source="Images/phone.png" Margin="20,0" x:Name="phone" Visibility="Visible">
                                <toolkit:GestureService.GestureListener>
                                    <toolkit:GestureListener Tap="GestureListener_Tap_Phone"/>
                                </toolkit:GestureService.GestureListener>
                            </Image>


                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox> 
  • 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. Editorial Team
    Editorial Team
    2026-05-20T02:42:40+00:00Added an answer on May 20, 2026 at 2:42 am

    You should create a binding for the image source instead of setting it explicitly in XAML.

    <ListBox x:Name="lbPharm" ItemsSource="{Binding col}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                    <TextBlock FontFamily="Segoe WP Semibold" FontWeight="Bold" FontSize="30" VerticalAlignment="Top" Margin="20,10">*</TextBlock>
                    <StackPanel>
                        <TextBlock x:Name="ItemText" Text="{Binding name}"  FontSize="{StaticResource PhoneFontSizeLarge}"/>
                        <TextBlock x:Name="ItemNumber" Text="{Binding number}"  FontSize="{StaticResource PhoneFontSizeNormal}"/>
                    </StackPanel>
    
                    <!-- Image source is bound to a property -->
                    <Image Source="{Binding ImageSource}" Margin="20,0" x:Name="phone" Visibility="Visible">
                        <toolkit:GestureService.GestureListener>
                            <toolkit:GestureListener Tap="GestureListener_Tap_Phone"/>
                        </toolkit:GestureService.GestureListener>
                    </Image>
    
    
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox> 
    

    Now, just update the property in your view model as needed, as long as the class containing the property implements INotifyPropertyChanged the new image will show up in your ListBox.

    The ImageSource property may have to be a BitmapImage instead of a string. XAML must use a converter to convert your path string when it is used as a literal but I think it doesn’t do this if you use a binding. Or you could use your own converter. Either way, construct a BitmapImage as follows:

    new BitmapImage( new Uri( "/path/to/image.png", UriKind.Relative ) )
    

    EDIT

    Adding an example:

    <DataTemplate x:Key="LongListSelectorItemTemplate">
      <StackPanel VerticalAlignment="Top"
                  Orientation="Horizontal">
    
        <toolkit:GestureService.GestureListener>
          <toolkit:GestureListener Tap="OnTap" />
        </toolkit:GestureService.GestureListener>
    
        <Image  Source="{Binding ImageSource}"
                MinHeight="32"
                MinWidth="32"
                MaxHeight="48"
                MaxWidth="48" />
    
        <StackPanel>
    
          <TextBlock Text="{Binding Name}"
                     Style="{StaticResource PhoneTextExtraLargeStyle}"
                     Margin="12,10,12,0" />
    
          <TextBlock Text="{Binding Parent}"
                     Foreground="{StaticResource PhoneAccentBrush}"
                     Style="{StaticResource PhoneTextSubtleStyle}"
                     Margin="24,0,12,10" />
    
        </StackPanel>
    
      </StackPanel>
    </DataTemplate>
    

    Corresponding view model:

    public class Item : INotifyPropertyChanged
    {
      #region Private Members
      private string _name = null; 
      private string _imageSource = null;
      private string _parent = null;
      #endregion
    
      public string Name
      {
        get
        {
          return _name;
        }
        set
        {
          if( value != _name ) {
            _name = value;
            NotifyPropertyChanged( "Name" );
          }
        }
      }
    
      public string Parent
      {
        get
        {
          return _parent;
        }
        set
        {
          if( value != _parent ) {
            _parent = value;
            NotifyPropertyChanged( "Parent" );
          }
        }
      }
    
      public string ImageSource
      {
        get
        {
          return _imageSource;
        }
        set
        {
          if( value != _imageSource ) {
            _imageSource = value;
            NotifyPropertyChanged( "ImageSource" );
          }
        }
      }
    
      #region INotifyPropertyChanged Members
      public event PropertyChangedEventHandler PropertyChanged;
      private void NotifyPropertyChanged( String propertyName )
      {
        PropertyChangedEventHandler handler = PropertyChanged;
        if( null != handler ) {
          handler( this, new PropertyChangedEventArgs( propertyName ) );
        }
      }
      #endregion
    }
    

    This is code from a project I’m working on, it is similar to your case except I’m displaying the image with a LongListSelector instead of a ListBox. And it looks like I mislead you earlier about not being able to use a string directly for the image source, I’m doing exactly that and it works. Sorry about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox that users can add/remove from. To add, there's a text
I have a Listbox that allows user to select multiple items. Normally user can
I have a listbox that a user can select multiple values from . each
I have a ListBox that is being bound to data from a WCF service.
I have a listbox that you can select users in. To the left of
I have a listbox that is bound to a List<T> -- this is working
I have a ListBox that can have multiple items selected at once. I have
Hey. I have a listbox that shows 3000 by 3000 pixel images (at 96
I have a listbox that should display data that contains 2 fields: time and
I have a listbox that uses a data template. The template is very simple

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.