Reputation: 6653
I have a BlogStore class which contains two observablecollections like so
public class BlogStore {
public ObservableCollection<Blog> blogs ...
public ObservableCollection<Blog> favourites ...
}
public BlogStore blogStore ...
no I want to reuse a control which does the following binding
ItemsSource="{Binding blogStore.blogs}
so that I can switch to favourites
, the following does not work, but I would like something in a similar vein.
ItemsSource={Binding blogStore{Binding category, ElementName=blogControl}
and in the controls code behind i would have a dependency property.
maybe a converter could do the trick?
Upvotes: 1
Views: 61
Reputation: 189437
If you treat BlogStore
as a ViewModel then it would expose a couple of other properties.
Category
to which you bind what ever control you are using to choose the category to display.
Also a CategoryBlogs
property which returns either the value of blogs
or favourites
depending on the value of Category
.
You would be implementing INotifyPropertyChanged
so you would ensure that a PropertyChanged
event is fired for "CategoryBlogs" when the Category
property is changed.
You would be binding ItemsSource
just to CategoryBlogs
.
Upvotes: 2