No bugs to fix, Yay!
Only some awesome new features, actually really nice extended and very useful features. With such a big take up of FreshMvvm we’ve ramped up the development. As always we take feedback and iterate on it so let us know of anything.
WhenAny
I’ve always loved the WhenAny feature in ReactiveUI and just wanted to have it. Not to mention it’s strongly typed which makes it so much better.
So now your ViewModels (or anything with INotifyPropertyChanged) you can subscribe to the changes of a property using the WhenAny features.
Here’s how you can use it:
C#
1
2
3
4
5
6
7
8
9
10
11
|
publicContactPageModel(IDatabaseService dataService)
{
_dataService=dataService;
this.WhenAny(HandleContactChanged,o=>o.Contact);
}
voidHandleContactChanged(stringpropertyName)
{
//handle the property changed, nice
}
|
Pushing different views
Another awesome feature that we’ve been loving is the ability to push with a different view. This means you can have multiple views for a single ViewModel.
Here’s the signature:
C#
1
|
Task PushPageModel<T,TPage>(objectdata,boolmodal=false)whereT:FreshBasePageModel where TPage:Page;
|
So it’s as easy as:
C#
1
|
PushPageModel<MyViewModel,MySecondView>();
|
Clean up after page is Popped
FreshBasePageModel now has a PageWasPopped event, this can be used to cleanup after a page has been Popped.
C#
1
2
3
4
5
|
/// <summary>
/// This event is raise when a page is Popped, this might not be raise everytime a page is Popped.
/// Note* this might be raised multiple times.
/// </summary>
publiceventEventHandler PageWasPopped;
|
We’ve linked up all the parts within the FreshMvvm project so that the event is always called and always called once, but this might not always be the case if you use a CustomNavigationService and don’t implement correctly.
This is a breaking change on the IFreshNavigationService as it now has a NotifyChildrenPageWasPopped().
If you have a custom navigation service you will need to implement this, here’s a sample of how the builtin master detail service handles it.
C#
1
2
3
4
5
6
7
8
9
10
|
publicvoidNotifyChildrenPageWasPopped()
{
if(Master isNavigationPage)
((NavigationPage)Master).NotifyAllChildrenPopped();
foreach(varpage inthis.Pages.Values)
{
if(page isNavigationPage)
((NavigationPage)page).NotifyAllChildrenPopped();
}
}
|
As always I love your feedback, please let me know how it do
Thanks