0

Im trying to create a simple WPF function where i press a buton, that increases the value of a variable of an object, this object is in a list and the list is used to give information to my DataGrid, but everything i press the button, i either have to refresh the application, or press the sorting options in the DataGrid for it to update.

Some stuff i have been thinking about to fix this would be a bindingList, but i cant seem to find how i do that in WPF.

List<Team> teams = new List<Team>();

        public MainWindow()
        {
            InitializeComponent();
            Team team = new Team();
            team.Name = "AIK";
            teams.Add(team);
            statsgrid.ItemsSource = teams;

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            teams[0].Mål++;
            statsgrid.ItemsSource = teams;

        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            statsgrid.ItemsSource = teams;

        }

This is the class, nothing extra..

    internal class Team
    {
        public string Name { get; set; }
        public int Matcher { get; set; }
        public int Mål { get; set; }
        public int Insläpp { get; set; }
        public int Målskillnad { get; set; }
        public int Vinster { get; set; }
        public int Lika { get; set; }
        public int Förluster { get; set; }
    }

The button, and where the information should be updated.

21sili
  • 35
  • 9
  • 2
    Use `ObservableCollection` instead of `List` and let the Team class implement the `INotifyPropertyChanged` interface. – Clemens Oct 31 '22 at 21:15

0 Answers0