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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:32:15+00:00 2026-06-05T00:32:15+00:00

I am trying to make ListBox which updates its content according to some changing

  • 0

I am trying to make ListBox which updates its content according to some changing data.
The XAML is as follows

StackPanel Orientation="Vertical">
<ListBox  x:Name="listWatch"  >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid ShowGridLines="True">
                <Grid Grid.Column="0" Background="{Binding Path=Color">
                    <TextBlock  Text="{ Binding Path=LTP}"  Padding="2 2 2 2"/>
                </Grid>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<Button x:Name="btn"  Click="btn_Click" Content="Button" />

The class i used for form data strucure is as follows

 public class WatchRow : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    string _color;
    decimal _lTP;

    public WatchRow(decimal LTP,string color)
    {         
        this.LTP = LTP;          
        this.Color = color;
    }
    public string Color 
    {
        get { return _color; }
        set{
            _color = value;
            OnPropertyChanged(_color);
        }
    }       
    public decimal LTP
    {
        get { return _lTP; }
        set
        {
            _lTP = value;
            OnPropertyChanged(_lTP.ToString());
        }
    }  
    protected void OnPropertyChanged(string info)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(info));
        }
    }
}

 public class Watch:ObservableCollection<WatchRow>
    {
        public Watch():base()
        {
        }       
    }

And the code behind file is like

    Watch watch = new Watch();
private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
{
    watch.Add(new WatchRow(132, "black"));
    watch.Add(new WatchRow(123, "red"));
    listWatch.ItemsSource = watch;  
watch[0].Color = "green";
}

private void btn_Click(object sender, RoutedEventArgs e)
{

    watch[0].Color = "green";
}

My problem is that i am not able to change the color of the list box item by setting the color property(watch[0].Color = “green”;) in btn_Click as shown in the code. But the same code works in PhoneApplicationPage_Loaded_1. I don’t know what i’m wrong. Any Ideas?

  • 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-05T00:32:16+00:00Added an answer on June 5, 2026 at 12:32 am

    I believe the problem is a slight change to how you are using PropertyChanged. When you are calling OnPropertyChanged, pass through the name of the property that you are changing, rather than the value. For example:

    public string Color 
        {
            get { return _color; }
            set{
                _color = value;
                OnPropertyChanged(_color);
            }
        }   
    

    Should be:

    public string Color 
        {
            get { return _color; }
            set{
                _color = value;
                OnPropertyChanged("Color");
            }
        }   
    

    Also, I’m not sure if this is necessarily a problem, but this is how I’ve always created the OnPropertyChanged function:

    Instead of:

    protected void OnPropertyChanged(string info)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(info));
        }
    }
    

    Try:

    private void OnPropertyChanged(String info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
    

    Also, as Magnus Johansson mentioned, define a brush, and bind the Color, rather than a string. So the Color property would be (see his explanation for further details on this):

    private Color _color;
    public Color Color 
            {
                get { return _color; }
                set{
                    _color = value;
                    OnPropertyChanged("Color");
                }
            }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a style for a listbox which will set the selected
I'm trying to make a ListBox that updates to the contents of an ObservableCollection
I've been trying for a while to display some data in a listbox/listview that
I have a ListBox in a Silverlight Application. I'm trying to make an editable
Trying to make a custom :confirm message for a rails form that returns data
trying to make a page which will recursively call a function until a limit
I'm trying to make a standard WPF listbox be dynamically filled, and for each
Working with a listbox in windows phone 7 I am trying to make an
The XAML below is basically trying to make a list of Button s (rendered
I am trying to make my ASP:Listbox throw an event in javascript that will

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.