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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:54:40+00:00 2026-05-17T22:54:40+00:00

I have a WPF (.Net 4) ListView used to navigate a local Windows directory.

  • 0

I have a WPF (.Net 4) ListView used to navigate a local Windows directory. It displays the contents of the current directory, with name and size and all that. However, in some directories, the first element it displays shows up twice. For example, let’s say in directory “D1” I have subdirectories “W”, “X”, “Y”, and “Z”. The ListView will say “W W X Y Z”, even though the actual data it’s bound to (a ThreadObservableCollection) doesn’t have the duplicate. The ThreadObservableCollection is also initially empty when the object that contains it is created, subdirectories and files are found on a background thread and then put in the collection as they are located.

I’m at a loss for how to even debug this, since it’s occurring purely in the presentation area, and am worried it may be a bug in the framework itself. It does not occur in every directory, but it seems (somewhat) repeatable in the ones it does occur in which suggests there’s some pattern at work here, though I’ve yet to find any distinguishing characteristics. It’s also always the first entry if it does happen.

I have also tried listening to the CollectionChanged event of the ThreadObservableCollection, but it only fires once per item changed as one would expect, and I’ve watched the values provided to ensure that there are no duplicates (which there aren’t).

I also attached a DebugConverter (see below) to the TextBlock containing the name of the (sub)directories shown, and it does show duplicate values. So there are definitely two actual rows in the ListView with the same item behind them, but I still have no idea why.

I’d appreciate any suggestions on what may be going wrong or even how to try to find out why it thinks it has to duplicate the first entry.

  • 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-17T22:54:41+00:00Added an answer on May 17, 2026 at 10:54 pm

    I would probably start by running it through a DebugConverter (you’ll have to write it, I don’t think there’s an implementation published with .Net). It looks like this:

    (Obviously, stick your breakpoint in VS at the single line of code in the method).

     public class DebugConverter : IValueConverter { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
          return value;    
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
    

    Now you can stick a breakpoint in, and verify that the duplicate is actually turning up at interface generation level. Examine the absolute path of the file (is it, for instance, the default “.” which represents the current directory, or something like that? Is it a misconversion somewhere else? I don’t know why that would only happen on some directories, but start by casting your debugging net wide).

    It probably isn’t a threading issue because to my mind the Dispatcher controls all interaction with the UI, including the observablecollection which backs your view, which means it can only interact serially. However, if you’re not using an ObservableCollection you might have threading? I suspect WPF is fairly strict about any backing enumeration, but I’m not sure. Oh, wait, you said you’re using an ObservableCollection. Okay, can’t be threading. Are you doing anything fancy with DataTemplateSelector? Is there a style which applies the view template? Could you have both the default Setter applying a style and a Trigger including another view item?

    Let’s try as hard as we can not to assume that it’s a bug in the framework. In my experience, the problem is ALWAYS my code, even if I don’t feel like it could be up front.

    (post comment)

    Even if your collection was empty at binding time you should be able to access the individual elements as they go in like this:

    <ListView>
     <ListView.ItemTemplate>
      <DataTemplate>
       <TextBlock Text='{Binding Path=filename, Converter={StaticResource DebugConverter}' />
      ...etc
      </DataTemplate>
     </ListView.ItemTemplate>
    </ListView>
    

    Any chance you can post your code?

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

Sidebar

Related Questions

I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a mixed UI (Win App, WPF App, and soon an ASP.NET MVC
Ok another WPF question, well I guess this is just general .NET. I have
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as
i have a problem with wpf-grid in .net-framework. I have defined a grid in
I have recently stumbled across an issue where the WPF ListView control seems to
I have a WPF .NET 3.5 SP1 application that is in use on at
I have a WPF .NET 4.0 class library referencing a Silverlight 4 class library.
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have a WPF project and I'm trying to setup a NAnt build script

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.