Hi,
I have the situation where I have a DP that returns a collection I receive from RIA Services, i.e. it is just a wrapper for data binding purposes. If I do the binding declaratively it does not work. However, if I do this in code it does. What could be the difference here?
My caller code that works is:
public class PlanBasePage { .....
private void SegmentSearch_SearchFinished(object sender, SearchFinishedEventArgs arg){// pass the results on to the gridif (!(arg.SearchResult is ReadOnlyObservableCollection<PlanningSegment>)) return;
SearchResult = arg.SearchResult
as ReadOnlyObservableCollection<PlanningSegment>; <----- Does not work i.e. SearchResult databinding to SegmentSearchResults.ItemsSource
SegmentSearchResults .ItemsSource = arg.SearchResult; <--------------- Works
public ReadOnlyObservableCollection<PlanningSegment> SearchResult{get { return (ReadOnlyObservableCollection<PlanningSegment>) GetValue(SearchResultProperty); }set { SetValue(SearchResultProperty, value); }}
My XAML data binding for SearchResult is:
<UserControls:RePlanBasePage x:Name="myPlanBasePage" ...> ....
<my:SegmentSearchResults x:Name="SearchResults" ItemsSource="{Binding SearchResult, ElementName=myPlanBasePage, Mode=OneWay}"
I have checked that all the values are correctly typed and contain the same values. BTW databinding is being done in Blend 3.0 using the data binding helper.
Graham
Hi Graham,
My guess is that you're not implementing INotifyPropertyChanged, and raising the PropertyChanged event for your SearchResult property.
You should add a PropertyChanged callback to your SearchResult DP, and when the property is changed, you will raise the PropertyChanged event off of your class.
If you don't know raise the event, then the binding never knows when the value changes, and thus never updates.
public static readonly DependencyProperty SearchResultProperty = DependencyProperty.Register("SearchResult", typeof(ReadOnlyObservableCollection<PlanningSegment>), typeof(YourOwningObject), new PropertyMetadata(null, new PropertyChangedCallback(SearchResultChanged)));
private static void SearchResultChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
YourOwningObject yoo = (YourOwningObject)obj;
yoo.OnPropertyChanged("SearchResult");
}
Hope this helps.
-SteveZ