BindingExpression not Valid for ListCollectionView in CollectionViewSource










-1















I need to have a collection displayed in a ListView. For that, i have a CompositeCollection with one ListViewItem as a searchbar for the collection. I put it together with a list of "n" items. The reason to do that, is that i need the searchbar is not influenced by sorting. The problem is, that the CollectionView i bind to a CollectionViewSource produces an BindingError and i don´t know why.



My XAML-Code for the Collections:



<Grid.Resources>
<CollectionViewSource x:Key="ElementSource" Source="Binding ElementsCollectionView"/>
<CompositeCollection x:Key="CompositeCollection">
<ListViewItem Content="Binding HeaderRow"/>
<CollectionContainer Collection="Binding Source=StaticResource ElementSource"/>
</CompositeCollection>
</Grid.Resources>


And the Collections I use



private NotifyCollection<DataEntry> _data;
public NotifyCollection<DataEntry> Data

get return this._data;
set this.SetProperty(ref this._data, value);


private CollectionView _elementsCollectionView;
public CollectionView ElementsCollectionView

get return this._elementsCollectionView;
set

if (value == null) return;
this._elementsCollectionView = value;



private CompositeCollection _tableItems;
public CompositeCollection TableItems

get return this._tableItems;
set this.SetProperty(ref this._tableItems, value);


private DataEntry _headerRow;
public DataEntry HeaderRow

get return this._headerRow;
set this.SetProperty(ref this._headerRow, value);



And the Collections being initalised:



public void SetCollection()

this.TableItems.Add(this.HeaderRow);
this.TableItems.Add(this.ElementsCollectionView);


this.TableViewModel.ElementsCollectionView =
(CollectionView)CollectionViewSource.GetDefaultView(this.Data);


As you can see, everything seem´s ok. The NotifyCollection inherits from ObservableCollection and should do hte work. If I add the HeaderRow to to the "ElementsCollectionView" everything works fine, except the HeaderRow is sorted. If i add the CollectionView to the CollectionViewSource, i get the BindingError:



 System.Windows.Data Error: 5 : Value produced by BindingExpression is 
not valid for target property.;
Value='System.Windows.Data.ListCollectionView'
BindingExpression:Path=ElementsCollectionView;
DataItem='AuftragsverwaltungDataTableViewModel' (HashCode=57170378);
target element is 'CollectionViewSource' (HashCode=52642430); target property is 'Source' (type 'Object')









share|improve this question


























    -1















    I need to have a collection displayed in a ListView. For that, i have a CompositeCollection with one ListViewItem as a searchbar for the collection. I put it together with a list of "n" items. The reason to do that, is that i need the searchbar is not influenced by sorting. The problem is, that the CollectionView i bind to a CollectionViewSource produces an BindingError and i don´t know why.



    My XAML-Code for the Collections:



    <Grid.Resources>
    <CollectionViewSource x:Key="ElementSource" Source="Binding ElementsCollectionView"/>
    <CompositeCollection x:Key="CompositeCollection">
    <ListViewItem Content="Binding HeaderRow"/>
    <CollectionContainer Collection="Binding Source=StaticResource ElementSource"/>
    </CompositeCollection>
    </Grid.Resources>


    And the Collections I use



    private NotifyCollection<DataEntry> _data;
    public NotifyCollection<DataEntry> Data

    get return this._data;
    set this.SetProperty(ref this._data, value);


    private CollectionView _elementsCollectionView;
    public CollectionView ElementsCollectionView

    get return this._elementsCollectionView;
    set

    if (value == null) return;
    this._elementsCollectionView = value;



    private CompositeCollection _tableItems;
    public CompositeCollection TableItems

    get return this._tableItems;
    set this.SetProperty(ref this._tableItems, value);


    private DataEntry _headerRow;
    public DataEntry HeaderRow

    get return this._headerRow;
    set this.SetProperty(ref this._headerRow, value);



    And the Collections being initalised:



    public void SetCollection()

    this.TableItems.Add(this.HeaderRow);
    this.TableItems.Add(this.ElementsCollectionView);


    this.TableViewModel.ElementsCollectionView =
    (CollectionView)CollectionViewSource.GetDefaultView(this.Data);


    As you can see, everything seem´s ok. The NotifyCollection inherits from ObservableCollection and should do hte work. If I add the HeaderRow to to the "ElementsCollectionView" everything works fine, except the HeaderRow is sorted. If i add the CollectionView to the CollectionViewSource, i get the BindingError:



     System.Windows.Data Error: 5 : Value produced by BindingExpression is 
    not valid for target property.;
    Value='System.Windows.Data.ListCollectionView'
    BindingExpression:Path=ElementsCollectionView;
    DataItem='AuftragsverwaltungDataTableViewModel' (HashCode=57170378);
    target element is 'CollectionViewSource' (HashCode=52642430); target property is 'Source' (type 'Object')









    share|improve this question
























      -1












      -1








      -1








      I need to have a collection displayed in a ListView. For that, i have a CompositeCollection with one ListViewItem as a searchbar for the collection. I put it together with a list of "n" items. The reason to do that, is that i need the searchbar is not influenced by sorting. The problem is, that the CollectionView i bind to a CollectionViewSource produces an BindingError and i don´t know why.



      My XAML-Code for the Collections:



      <Grid.Resources>
      <CollectionViewSource x:Key="ElementSource" Source="Binding ElementsCollectionView"/>
      <CompositeCollection x:Key="CompositeCollection">
      <ListViewItem Content="Binding HeaderRow"/>
      <CollectionContainer Collection="Binding Source=StaticResource ElementSource"/>
      </CompositeCollection>
      </Grid.Resources>


      And the Collections I use



      private NotifyCollection<DataEntry> _data;
      public NotifyCollection<DataEntry> Data

      get return this._data;
      set this.SetProperty(ref this._data, value);


      private CollectionView _elementsCollectionView;
      public CollectionView ElementsCollectionView

      get return this._elementsCollectionView;
      set

      if (value == null) return;
      this._elementsCollectionView = value;



      private CompositeCollection _tableItems;
      public CompositeCollection TableItems

      get return this._tableItems;
      set this.SetProperty(ref this._tableItems, value);


      private DataEntry _headerRow;
      public DataEntry HeaderRow

      get return this._headerRow;
      set this.SetProperty(ref this._headerRow, value);



      And the Collections being initalised:



      public void SetCollection()

      this.TableItems.Add(this.HeaderRow);
      this.TableItems.Add(this.ElementsCollectionView);


      this.TableViewModel.ElementsCollectionView =
      (CollectionView)CollectionViewSource.GetDefaultView(this.Data);


      As you can see, everything seem´s ok. The NotifyCollection inherits from ObservableCollection and should do hte work. If I add the HeaderRow to to the "ElementsCollectionView" everything works fine, except the HeaderRow is sorted. If i add the CollectionView to the CollectionViewSource, i get the BindingError:



       System.Windows.Data Error: 5 : Value produced by BindingExpression is 
      not valid for target property.;
      Value='System.Windows.Data.ListCollectionView'
      BindingExpression:Path=ElementsCollectionView;
      DataItem='AuftragsverwaltungDataTableViewModel' (HashCode=57170378);
      target element is 'CollectionViewSource' (HashCode=52642430); target property is 'Source' (type 'Object')









      share|improve this question














      I need to have a collection displayed in a ListView. For that, i have a CompositeCollection with one ListViewItem as a searchbar for the collection. I put it together with a list of "n" items. The reason to do that, is that i need the searchbar is not influenced by sorting. The problem is, that the CollectionView i bind to a CollectionViewSource produces an BindingError and i don´t know why.



      My XAML-Code for the Collections:



      <Grid.Resources>
      <CollectionViewSource x:Key="ElementSource" Source="Binding ElementsCollectionView"/>
      <CompositeCollection x:Key="CompositeCollection">
      <ListViewItem Content="Binding HeaderRow"/>
      <CollectionContainer Collection="Binding Source=StaticResource ElementSource"/>
      </CompositeCollection>
      </Grid.Resources>


      And the Collections I use



      private NotifyCollection<DataEntry> _data;
      public NotifyCollection<DataEntry> Data

      get return this._data;
      set this.SetProperty(ref this._data, value);


      private CollectionView _elementsCollectionView;
      public CollectionView ElementsCollectionView

      get return this._elementsCollectionView;
      set

      if (value == null) return;
      this._elementsCollectionView = value;



      private CompositeCollection _tableItems;
      public CompositeCollection TableItems

      get return this._tableItems;
      set this.SetProperty(ref this._tableItems, value);


      private DataEntry _headerRow;
      public DataEntry HeaderRow

      get return this._headerRow;
      set this.SetProperty(ref this._headerRow, value);



      And the Collections being initalised:



      public void SetCollection()

      this.TableItems.Add(this.HeaderRow);
      this.TableItems.Add(this.ElementsCollectionView);


      this.TableViewModel.ElementsCollectionView =
      (CollectionView)CollectionViewSource.GetDefaultView(this.Data);


      As you can see, everything seem´s ok. The NotifyCollection inherits from ObservableCollection and should do hte work. If I add the HeaderRow to to the "ElementsCollectionView" everything works fine, except the HeaderRow is sorted. If i add the CollectionView to the CollectionViewSource, i get the BindingError:



       System.Windows.Data Error: 5 : Value produced by BindingExpression is 
      not valid for target property.;
      Value='System.Windows.Data.ListCollectionView'
      BindingExpression:Path=ElementsCollectionView;
      DataItem='AuftragsverwaltungDataTableViewModel' (HashCode=57170378);
      target element is 'CollectionViewSource' (HashCode=52642430); target property is 'Source' (type 'Object')






      c# wpf mvvm data-binding collections






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 11:03









      S. SeidelS. Seidel

      64




      64






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can't set the Source property of a CollectionViewSource to a ListCollectionView. This will throw an ArgumentException. Sort the NotifyCollection<DataEntry> collection and bind to this one instead.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279599%2fbindingexpression-not-valid-for-listcollectionview-in-collectionviewsource%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can't set the Source property of a CollectionViewSource to a ListCollectionView. This will throw an ArgumentException. Sort the NotifyCollection<DataEntry> collection and bind to this one instead.






            share|improve this answer



























              0














              You can't set the Source property of a CollectionViewSource to a ListCollectionView. This will throw an ArgumentException. Sort the NotifyCollection<DataEntry> collection and bind to this one instead.






              share|improve this answer

























                0












                0








                0







                You can't set the Source property of a CollectionViewSource to a ListCollectionView. This will throw an ArgumentException. Sort the NotifyCollection<DataEntry> collection and bind to this one instead.






                share|improve this answer













                You can't set the Source property of a CollectionViewSource to a ListCollectionView. This will throw an ArgumentException. Sort the NotifyCollection<DataEntry> collection and bind to this one instead.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 12:14









                mm8mm8

                83.3k81931




                83.3k81931





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279599%2fbindingexpression-not-valid-for-listcollectionview-in-collectionviewsource%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20