Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi guys need some help please.
I've got a ListView. The ListView is bound to one of the properiets which is a collection ex. Item Source={Binding Collection1} . In C# the code I have got this: ListView.DataContext=name of the object. That is working but...
The thing is that properties that are going to be displayed change depends on what the user wants to see.
For example user chooses differnt category and I want the ListView to display Properties2 not Properies1, but Item Source for the ListView is already set to Property1. What is the simplest way to fix this?
Thanks for help in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 7-Mar-15 11:41am    
I would think about building a single data source integrating data sources you have.
—SA
Reatellino 9-Mar-15 6:58am    
heheh Came up with the same idea. Thanks a lot:)
Sergey Alexandrovich Kryukov 9-Mar-15 8:33am    
You are welcome.
—SA

I would suggest using an item view model as a wrapper for the objects that you wish to display. The objects could implement an interface that defines a method to display the data. Then bind a property in the view model to the items display in the view. This property would call the model’s display method in its getter. Something like.


C#
public   interface IDisplayItem
    {
        string GetDisplayString();
        ..........................
    }

  public  class ItemViewModel
  {
      private readonly IDisplayItem item;
      public ItemViewModel(IDisplayItem obj)
      {
          item = obj;
      }

      public string ItemDisplay
      {
          get
          {
              return item.GetDisplayString();
          }
      }
     ....................................
    }
}

You can then change the items collection as needed without changing the bindings in the view.

 
Share this answer
 
Decided to build one general source which includes two different and use it as a source of the list view:)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Mar-15 8:33am    
Doesn't this just repeat the idea I suggested you in my comment to the question? Why posting it as a "solution"?
—SA
Reatellino 9-Mar-15 8:38am    
I'm new to the forum, and wasn't sure where to put it. sorry upps.
Sergey Alexandrovich Kryukov 9-Mar-15 8:44am    
Not a problem, but... Please keep in mind that certain posts are considered as abuse, be some obvious reasons: non-questions as questions, re-posted questions, non-answers as "solutions", and the like. You can use comments and/or "Improve question". Also, the author of any post receives a notification of someone comments on it, but not if you add some independent post.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900