|
-
Jun 7th, 2011, 01:22 AM
#5
Re: Binding to a read-only property that returns a NEW collection of objects
 Originally Posted by Evil_Giraffe
I would also suggest that having a collection of controls is working somewhat counter to the spirit of WPF. You should be exposing collections of domain classes - so instead of a DayControlCollection containing DayControls, I would expect a DayCollection containing Day instances. Your XAML can then define a DataTemplate that says for a Day instance, render it with a DayControl. The DayCollection would be bound as the ItemsSource of a CollectionControl which has its ItemsPanel template set to lay it out in the calendar style, and so on.
Completely agree, but I did not get that to work. I needed this in a hurry so I didn't have time to figure out how to do it exactly. The problem is was the layout of the day controls; if the window is very wide of course the day controls should become wider as well (in my case it just placed more controls on one line), and also the day names above (Sunday, Saturday, ...) would need to stretch along with the day controls (they should of course stay centered above it).
There certainly is a way better way to construct my control but I simply didn't see it, so I did it the easy way. I guess it is coming back to bite me 
 Originally Posted by Evil_Giraffe
You do not need to raise the PropertyChanged event for Appointments property here. The value of the property has not changed (it is still the same collection returned). What has changed is the contents of the collection, but WPF is notified about that via the INotifyCollectionChanged interface of the observable nature of the collection.
True, I was just trying if that helped.
 Originally Posted by Evil_Giraffe
Another option is to bind the ListBox to the complete collection of appointments exposed at the top level, and then grab the CollectionView from it and alter that depending on which Day is selected by setting the Filter on it. This will then only display the appointments from the collection that match the predicate supplied (appointment.Date == selectedDay.Date)
I like that even better; I've never heard of 'grabbing a CollectionView'. I suppose you can easily filter a collection and display only the part that matches a predicate? The DayControl could then just display all appointments and just filter them on the date.
Thanks, I will check this out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|