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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:19:13+00:00 2026-05-25T00:19:13+00:00

Hi Im trying to bind a ListView to a Linq, and make it react

  • 0

Hi Im trying to bind a ListView to a Linq, and make it react on changes in the collection.

public partial class MainWindow
{
    readonly ObservableCollection<Person> _persons = new ObservableCollection<Person>();
    readonly Team _team1 = new Team { Name = "Team 1" };
    readonly Team _team2 = new Team { Name = "Team 2" };
    readonly Team _team3 = new Team { Name = "Team 3" };

    public MainWindow()
    {
        InitializeComponent();

        _persons.Add(new Person {Name = "James", Team = _team1});
        _persons.Add(new Person {Name = "John", Team = _team2});
        _persons.Add(new Person {Name = "Peter", Team = _team3});
        _persons.Add(new Person {Name = "Jack", Team = _team1});
        _persons.Add(new Person {Name = "Jones", Team = _team2});
        _persons.Add(new Person {Name = "Bauer", Team = _team3});
        _persons.Add(new Person {Name = "Bo", Team = _team1});
        _persons.Add(new Person {Name = "Ben", Team = _team2});
        _persons.Add(new Person {Name = "Henry", Team = _team3});

        TeamList1.ItemsSource = from person in _persons where person.Team == _team1 select person;
        TeamList2.ItemsSource = from person in _persons where person.Team == _team2 select person;
        TeamList3.ItemsSource = from person in _persons where person.Team == _team3 select person;
    }

    private void ButtonClick(object sender, RoutedEventArgs e)
    {
        _persons[0].Team = _team2;
    }
}

And my Models

 public class Person : INotifyPropertyChanged
    {
        private string _name;
        public String Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }

        private Team _team;
        public Team Team
        {
            get { return _team; }
            set { _team = value; NotifyPropertyChanged("Team"); }
        }

        public override string ToString()
        {
            return string.Format("Name {0}\t{1}", Name, Team);
        }
        public event PropertyChangedEventHandler PropertyChanged;

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

    public class Team : INotifyPropertyChanged
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }

        public override string ToString()
        {
            return Name;
        }
        public event PropertyChangedEventHandler PropertyChanged;

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

And the Xaml

<Grid>
        <StackPanel Orientation="Vertical">
        <StackPanel>
            <ListView Name="TeamList1"/>
            <ListView Name="TeamList2"/>
            <ListView Name="TeamList3"/>
        </StackPanel>
            <Button Content="Click Me" Click="ButtonClick"/>
        </StackPanel>
    </Grid>

When the ButtonClick is called I would like my ListView to reflect the changes it made on the _persons.

  • 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-25T00:19:14+00:00Added an answer on May 25, 2026 at 12:19 am

    Just don’t use linq, there are CollectionViews for this sort of thing which have filters, you then only have to refresh the views (See: How to: Filter data in a view). (If you must use linq there are also bindable extensions to it)

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

Sidebar

Related Questions

I am trying to bind a grouped linq statement to a asp.net listview. Problem
I am trying to bind a data class to a ListView control in WPF,
I have a listview who's itemssource is a ObservableCollection of MyModel. I am trying
I'm trying to bind a HashSet to a ListView item. I've documented my code
I have a following ListView item template, in which I am trying to bind
Here's the ListAdapter that I am trying to bind my ListView with. ListAdapter adapter
I have a class like: class EditorViewModel { public ObservableCollection<Effect> AllEffects; public bool HasPermissions;
I'm trying to bind some data to a WPF listview. One of the properties
I'm trying to bind data from my SQLiteDatabase to a ListView . I'm currently
Im trying to bind a dropdownlist in ASP.NET MVC to a class. Luckily for

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.