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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:20:26+00:00 2026-05-31T05:20:26+00:00

I have the following code in xaml: <ListView Name=listView1 IsSynchronizedWithCurrentItem=True > <ListView.View> <GridView> <GridViewColumn

  • 0

I have the following code in xaml:

    <ListView Name="listView1" IsSynchronizedWithCurrentItem="True" >
        <ListView.View>
            <GridView>
                <GridViewColumn Header="MyList">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Cost, Mode=TwoWay}"></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

on my code behind I have:

public partial class LogIn : UserControl,  INotifyCollectionChanged
{
    class Product
    {
        public string Name { get; set; }
        public int Cost { get; set; }
    }

    ObservableCollection<Product> MyList = new ObservableCollection<Product>()
    {
        new Product(){ Cost=14},
        new Product(){ Cost=15},
        new Product(){ Cost=5},
        new Product(){ Cost=20}
    };

    event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
    {
        add { throw new NotImplementedException(); }
        remove { throw new NotImplementedException(); }
    }

    // constructor
    public LogIn()
    {
        InitializeComponent();

        listView1.DataContext = MyList;
    }

    private void button5_Click(object sender, RoutedEventArgs e)
    {
        this.MyList[0].Cost = 123456789;
        // !!!!!!!!!!!!!!! I want the listview to update when I press this button
    }

The listview does not change when I update on the last method. what do I have to do so that I can update the listview cost values with code behind?


Edit

Thanks to SLaks I made the following changes to my Product class and it worked.

    public class Product : INotifyPropertyChanged
    {
        private int _cost;
        public string Name { get; set; }
        public int Cost
        {
            get
            {
                return _cost;
            }
            set
            {
                _cost = value; 
                OnPropertyChanged("Cost");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        private void OnPropertyChanged(string propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

also I added the following line in the constructor of the usercontroll:

   listView1.ItemsSource = MyList;
  • 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-31T05:20:27+00:00Added an answer on May 31, 2026 at 5:20 am

    You need to implement INotifyPropertyChanged in the Product class so that WPF knows when your properties change.

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

Sidebar

Related Questions

I have the follwoing listview in my xaml: <ListView Name=listView1> <ListView.View> <GridView> <GridViewColumn Width=Auto
I have the following XAML Code: <sdk:DataGrid Margin=58,8,52,18 Name=dataGridTickets> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn x:Name=ticketNoColumn Header=Ticket No.
I have the following wpf control added to xaml: <ListView Margin=22,80,271,12 Name=listView1 ItemsSource={Binding} />
I have the following code in XAML: <data:DataGridTemplateColumn> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Image x:Name=picture Width=200 Height=130
In XAML I have the following code: <Label Width=120 Height=20 Name=label1 SnapsToDevicePixels=True HorizontalAlignment=Left VerticalAlignment=Bottom>
Hi I have following XAML code which is the output from XamlWriter.Save(): <StackPanel Name=itemStack
I have the following xaml-Code: <Border x:Name=border> <Border.Style> <Style TargetType={x:Type Border}> <Style.Triggers> <DataTrigger Binding={Binding
I have the following XAML code as part of a custom control: <telerik:RadTreeView x:Name=treeModules>
I have the following XAML code, which displays a picture (image inside borders) and
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.