I have a data navigation user control in Silverlight which opens a child window where the user can enter search criteria and when they press ‘Apply’ it’s suppose to update the bound property in the ViewModel (MVVM pattern.)
The links are: SearchDialog <–> DataNavigator <–> MyView <–> MyViewModel
The dependency property in SearchDialog seems to work, when I set its value, it shows up in DataNavigator; however when the dependency property changes, no notification seems to be sent from DataNavigator to MyView/MyViewModel.
SearchDialog derives from ChildWindow:
public string Search
{
get { return (string)GetValue(SearchProperty); }
set { SetValue(SearchProperty, value); }
}
public static readonly DependencyProperty SearchProperty =
DependencyProperty.Register("Search", typeof(string), typeof(SearchDialog),
new PropertyMetadata(null));
DataNavigator derives from UserControl:
public Binding Search { get; set; }
private void DataNavigator_Loaded(object sender, Windows.RoutedEventArgs e)
{
if (Search != null)
this._searchDialog.SetBinding(SearchDialog.SearchProperty, Search);
}
MyView derives from SilverlightFX.UserInterface.Navigation.Page:
<DataNavigator MovePreviousAction="$model.MovePrevious()"
CurrentIndex="{Binding CurrentIndex, Mode=TwoWay}"
MoveNextAction="$model.MoveNext()"
SaveAction="$model.SaveChanges()"
IsLoading="{Binding IsLoading, Converter={StaticResource VisibilityConverter}}"
Search="{Binding SearchString, Mode=TwoWay}"/>
MyViewModel derives from ViewModel:
public string SearchString
{
get { return this._search; }
set
{
if(value != this._search)
{
this._search = value;
this.RaisePropertyChanged("SearchString");
}
}
}
I’ve been trying for hours to find the problem but haven’t had any success; anyone see the issue? Thanks in advance,
Bryant’s solution looks like the right way to go but I still had some problems. I did end up getting this to work using the following approach:
I added an event to SearchDialog that would fire whenever the search pattern DP changed:
After this I just added another DP in the DataNavigator:
And then hooked up the Navigator’s DP to the SearchDialog’s DP so that changes to the Search property would be propagated through to the DataNavigator which is then bound to the V & VM.
The rest of things remain the same as above and I’m getting the effect I was looking for.