I've got similar situation to this, but in Touch. Trying to deal with that via INotifyPropertyChanged though.
My code is the following:
set.Bind(txtSearch).For(x => x.Text).To(x => x.SearchText);
where txtSearch is my custom wrapper of UISearchBar. So, I can not inherit from MvxNotifyPropertyChanged as I already inherit from UIView (the wrapper is view).
Text property is:
public string Text { get
{
return _search.Text;
} set
{
_search.Text = value;
RaisePropertyChanged(() => Text);
}
}
and I fire it on the SearchBar text changing (which works).
I've also added the following:
public event PropertyChangedEventHandler PropertyChanged;
protected IMvxMainThreadDispatcher Dispatcher
{
get { return MvxMainThreadDispatcher.Instance; }
}
protected void InvokeOnMainThread(Action action)
{
if (Dispatcher != null)
Dispatcher.RequestMainThreadAction(action);
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> property)
{
var name = this.GetPropertyNameFromExpression(property);
RaisePropertyChanged(name);
}
protected void RaisePropertyChanged(string whichProperty)
{
var changedArgs = new PropertyChangedEventArgs(whichProperty);
RaisePropertyChanged(changedArgs);
}
protected void RaisePropertyChanged(PropertyChangedEventArgs changedArgs)
{
// check for subscription before going multithreaded
if (PropertyChanged == null)
return;
InvokeOnMainThread(
() =>
{
var handler = PropertyChanged;
if (handler != null)
handler(this, changedArgs);
});
}
But when everything gets to RaisePropertyChanged, then I see that PropertyChanged is empty (so, seems no code is subscribed for my object). Which, of course, makes no notifications further.
I have similar situation but with some object inherited directly from MvxNotifyPropertyChanged, which seems working fine. Does that mean, that MvvmCross only can deal with such objects but not ones which generally use INotifyPropertyChanged?
Thank you!