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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:31:24+00:00 2026-06-16T23:31:24+00:00

I have a class that is bound to a ListBox: class FolderFM : INotifyPropertyChanged

  • 0

I have a class that is bound to a ListBox:

class FolderFM : INotifyPropertyChanged
{
    public FolderFM(string path)
    {
        this.Folder = new DirectoryInfo(path);
        this.Name = Folder.Name;
    }

    private string name;
    private DirectoryInfo folder;
    private ObservableCollection<FileInfo> matchingFiles;

    ...

    public ObservableCollection<FileInfo> MatchingFiles 
    {
        get { return matchingFiles; }
        set
        {
            matchingFiles = value;
            FireWhenPropertyChanged("MatchingFiles");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void FireWhenPropertyChanged(string property)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(property, new PropertyChangedEventArgs(property));
        }
    }
}

XAML Code:

<ListBox Name="lstFolders" ItemsSource="{Binding}" Style="{StaticResource FolderBoxStyle}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="25" />
                            </Grid.ColumnDefinitions>
                            <Label Content="{Binding Path=Name}" FontWeight="Bold" FontSize="13" />
                            <Button Content="{Binding Path=MatchingFiles, Converter={StaticResource lcc}}" Grid.Column="1" FontWeight="Bold" Foreground="Red" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Code-Behind where the update is taking place:

private void btnAnalyze_Click(object sender, RoutedEventArgs e)
    {
        List<FileInfo> remainingFiles = files;
        foreach (FolderFM currentFolder in folders)
        {
            currentFolder.MatchingFiles = new ObservableCollection<FileInfo>();
            string folderName = currentFolder.Folder.Name;
            string[] splitName = folderName.Split(' ');
            for (int i = 0; i < remainingFiles.Count; i++)
            {
                if (remainingFiles[i] == null)
                    continue;
                FileInfo fileName = remainingFiles[i];
                string searchedName = fileName.Name;
                matchScore = 0;
                int searchCount = 0;
                foreach (string part in splitName)
                {
                    if (part.Length < 3 || part == "the")
                        continue;
                    matchScore += searchedName.Contains(part) ? 1 : 0;
                    searchCount += 1;
                }
                if (matchScore == searchCount)
                {
                    string destination = System.IO.Path.Combine(currentFolder.Folder.FullName, fileName.Name);
                    if (File.Exists(destination))
                        continue;
                    Directory.Move(fileName.FullName, destination);
                    currentFolder.MatchingFiles.Add(remainingFiles[i]);
                    //lstFolders.Items.Refresh();
                    remainingFiles[i] = null;
                }
            }
        }
        populateFiles();
    }

The attached Converter accepts the ObservableCollection and returns it’s Count as string.

The application is working properly and the values are being updated but the changes are not being reflected on the UI.

However when I call:
lstFolders.Items.Refresh();
the UI gets updated.

What am I missing/doing wrong ??

I looked at a few questions like:
WPF Binding with INotifyPropertyChanged does not update
but haven’t been able to solve this problem.

Edit:

The DataContext is being assigned by this method:

private void populateFolders()
    {
        folders = getFolders(selectedFolder.FullName);
        lstFolders.ItemsSource = folders;
    }

private List<FolderFM> getFolders(string path)
    {
        List<FolderFM> d = new List<FolderFM>();
        foreach (string folder in Directory.GetDirectories(path))
        {
            d.Add(new FolderFM(folder));
        }
        return d;
    }
  • 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-16T23:31:25+00:00Added an answer on June 16, 2026 at 11:31 pm

    Converting my comment into an answer:

    Try binding directly to MatchingFiles.Count.

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

Sidebar

Related Questions

I have class that looks like this: class A { public: class variables_map vm
I have an XML file that is bound to a listbox as below. This
I have a class called Book; class Book { public string Name { get;
I have a Class that has a private variable with a public setter/getter function:
I have a class that is bound to GUI elements as follows: <TextBox Style={StaticResource
I have a Combobox that is bound to an ObservableCollection<Source>. In the class there
I have a user control that inherits from the ListBox class and displays a
I have a ListBox which is bound to ObservableCollection of LogMessages. public ObservableCollection<LogMessage> LogMessages
I have a DataTable that I'm converting to a model which implements INotifyPropertyChanged. This
I have a ListBox data bound to the collection of my PersonCollection class. Next,

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.