Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF collections
I'm unable to Create CollectionViewSource with the Collection,I have an XML file and Deserilized it to get Collection,
XML File
<?xml version="1.0" encoding="utf-8" ?>
<Stack Id="001" Name="KEYABLE">
  <Pages PageName="Stack1">
    <Page PT="ENVELOPE" >
        <File FN="C:\Work\002885118s51128444038\PageCode\X11090_0009_001\X11090_0009_001_001.tif" FF="TIFF" Index="1"/>
    <Page PT="UNKNOWN">
        <File FN="C:\Work\002885118s51128444038\PageCode\X11090_0009_001\X11090_0009_001_001.tif" FF="TIFF" Index="2"/>
<Stack Id="002" Name="KEYABLE">
  <Pages PageName="Stack2">
    <Page PT="ENVELOPE">
        <File FN="C:\Work\002885118s51128444038\PageCode\X11090_0009_001\X11090_0009_001_003.tif" FF="TIFF" Index="1"/>
    <Page PT="UNKNOWN">
        <File FN="C:\Work\00288511851128436351\N12208_0000_020\00000059.tif" FF="TIFF" Index="2"/>
and i set DataContext to my Usercontrol with the Deserilized Collection,DataContext has been set perfectly.
Public Sub New()
            Dim Reader As New Xml.XmlTextReader("F:\WPFSample Apps\TabControl--DynamicTab\WPFDyanamicTab_vb\XMLFile.xml")
            Dim oStack As New Stacks
            oStack = Sympraxis.Capture.Common.XObjectBase.OpenXml(Reader, oStack.GetType)
            Me.DataContext = oStack
    Dim myCollectionView As ListCollectionView
            myCollectionView = CType(CollectionViewSource.GetDefaultView(Me.DataContext), ListCollectionView)
        End Sub
when i assign it to myCollectionView ,i'm getting "Nothing" in MycollectionView,
This is a collection contains List of Collections.
when i worked with simple collection its working perfect,but this is not happening in my case,how can i achieve it?
Posted 27-Jun-13 3:16am
Edited 27-Jun-13 3:28am
Pheonyx at 27-Jun-13 8:28am
Are you getting any exceptions being thrown?
If so what does the exception say?
Pheonyx at 27-Jun-13 8:42am
If you step through the code, do you get a valid response if you put :
CollectionViewSource.GetDefaultView(Me.DataContext) in a watch window?
kumar.selva.c at 28-Jun-13 2:17am
Actually when i set oStack to Me.datacontext its perfect, But when i set it to myCollectionView = CType(CollectionViewSource.GetDefaultView(Me.DataContext), ListCollectionView), i'm getting mycollectionView = Nothing
and exception has not been thrown.
Pheonyx at 28-Jun-13 2:56am
My point was more, what happens if you don't do the casting just the CollectionViewSource.GetDefaultView(Me.DataContext) bit.
kumar.selva.c at 28-Jun-13 3:23am
@Pheonyx, Its also not working , but when i do like this
myCollectionView = CType(CollectionViewSource.GetDefaultView(DirectCast(DataContext, ThumbnailImages_Test.Stacks).Stacks), ListCollectionView)
i'm able to get mycollectionview but still, since this is multiple collection i'm unable to group and sort.
If it is a single collection, CollectionViewSorurce works perfectly, i don how to deal with list of Collection , if you see the above XML file there are two stack collection which in turn cointains many collection,
i want to group by "PT" and Filter by Index which is inside the File Collection and to load images in Filename,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 450
1 Suvendu Shekhar Giri 130
2 Abhinav S 126
3 Jochen Arndt 100
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,870
2 Peter Leow 4,984
3 Kornfeld Eliyahu Peter 3,300
4 Maciej Los 2,456

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 27 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100