none
WPF Observable collection binding

    Question

  • I am using observable collection to bind the tree view. I could successfully bind the data without any issue. My problem is after searching a the items in tree i could the search results. But i couldn't bind the search results in UI. Always it shows all the data in tree

    mohav

    Friday, February 09, 2018 6:08 PM

All replies

  • After doing something unspecified you saw no difference.

    I wonder what you did.

    .

    If you used a collectionview like here:

    https://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx#Filtering

    You need to force re-read of the collection. The filter is only applied when it's read.

    And of course a treeview has collections within collections.

    Meaning you might find it best to rebuild your tree of data entirely.

    In either case, you'd probably want to also raise propertychanged on the property the itemssource of the treeview is bound to so the treeview goes and gets the data again.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, February 09, 2018 8:51 PM
    Moderator
  • Hi mohav,

    >>My problem is after searching a the items in tree i could the search results. But i couldn't bind the search results in UI. Always it shows all the data in tree .

    Can you show the code to indicate what  you're trying to solve?

    In WPF, you can use CollectionView  for grouping, sorting, filtering, and navigating a data collection.

    You can think of a collection view as a layer on top of a binding source collection that allows you to navigate and display the collection based on sort, filter, and group queries, all without having to manipulate the underlying source collection itself.

    Because a view does not change the underlying source collection, a source collection can have multiple views associated with it. By using views, you can display the same data in different ways.

    Here is a sample:How to: Filter Data in a View

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 13, 2018 7:27 AM
    Moderator