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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:59:53+00:00 2026-06-14T11:59:53+00:00

Has appeared a strange situation with listboxitem inner sender (i just think that this

  • 0

Has appeared a strange situation with listboxitem inner sender (i just think that this sender is to blame, but not sure…)

There is ItemTemplate for ListBox:

<ListBox x:Name="list">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel x:Name="stack_panel">
                    <Image Source="{Binding ImageSource}" Tap="Image_Tap"></Image>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
</ListBox>

Every item in ListBox has a some image with tap event:

private void Image_Tap(object sender, GestureEventArgs e)
{
   Image i = (Image)sender;
   i.Source = new BitmapImage(new Uri("Images/yellow.png", UriKind.RelativeOrAbsolute));
}

Also, there is a class for easy images changing:

public class listItems
{
    public string ImageSource { get; set; }
}

Right. Now i ready to add some elements in listbox:

for (int i = 0; i < 100;i++)
   list.Items.Add(new listItems
   {
       ImageSource = "Images/black.png"
   });

So, let’s click on zeroth sun image:

image 1

Everything is ok! Let’s continue, and click on a second picture:

image 2

Right, the sun is shining..but.. stop, what is that? 0_o

enter image description here

I didn’t click on this item, but image of this has changed! That happens with not only th item, also it has been with some other random items (53, 81, …)

What do you think about this? Can sender has reference to many elements?

  • 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-06-14T11:59:55+00:00Added an answer on June 14, 2026 at 11:59 am

    What do you think about this?

    By default list box control reuses visual items to optimize the performance. You can switch it off if you want, however for your 100 items the performance will drop of course.

    There’s better solution. Instead of what you’re doing, you should store the selection state somewhere in your model, not just in a visual tree.

    Your item class could be:

    public class listItems: INotifyPropertyChanged
    {
        bool _selected = false;
        public bool isSelected
        {
            get { return _selected; }
            set 
            {
                if( value == _selected )
                    return;
                _selected = value;
                var pc = this.PropertyChanged;
                if( null != pc )
                    pc( this, new PropertyChangedEventArgs( "ImageSource" ) );
            }
        }
    
        public string ImageSource { get { return _selected ? "Images/yellow.png" : "Images/black.png"; } }
    
        public event PropertyChangedEventHandler PropertyChanged;
    }
    

    INotifyPropertyChanged interface allows the visual tree to be notified about the property changes.

    And here’s the tap handler:

    void Image_Tap( object sender, GestureEventArgs e )
    {
        Image img = (Image)sender;
        listItems item = (listItems)img.DataContext;
        item.isSelected = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm aware that this question has appeared in various forms before, but none of
Error below are fixed by removing the declaration but another has appeared that did
I know this question has appeared few times, but the things are changing really
Here's a strange bug that appears on the iPhone (4S) but not the iPad
I want to find the first element that has appeared in previous positions in
I have an image that I wish to animate after a view has appeared.
I need to know, whether a vertical scrollbar has appeared or not in browser
How do I remove the \002 char that has appeared in my string in
my app is nearly finished but a leak has appeared. After having spent an
Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that

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.