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?
If you treat
BlogStoreas a ViewModel then it would expose a couple of other properties.Categoryto which you bind what ever control you are using to choose the category to display.Also a
CategoryBlogsproperty which returns either the value ofblogsorfavouritesdepending on the value ofCategory.You would be implementing
INotifyPropertyChangedso you would ensure that aPropertyChangedevent is fired for “CategoryBlogs” when theCategoryproperty is changed.You would be binding
ItemsSourcejust toCategoryBlogs.