Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Few question from a newbie - MVVM, ViewModels and sln folders structure

$
0
0

Hey, I'm new into XF it's my third day of learning.

I didn't saw any FAQ of how questions should look so I will make one post with few.

First one, how your solution structure looks like? Default it's specific platform projects like "SolutionName.Droid" etc. and one project for entire shared code.
It's good or you making more project for shared code?

Second one, I have tabbed page with two content page.
App.xaml.cs:
this.MainPage = new NavigationPage(new MainPage());
From MainPage
this.Navigation.PushAsync(new MyTabbedPage());

MainPage.xaml.cs
`
MyTabbedPageViewModel vm = new MyTabbedPageViewModel(data);
this.BindingContext = vm;

this.Children.Add(new DetailsPage
{
    Title = "Details",
        BindingContext = vm
});
this.Children.Add(new AttendanceListPage
{
    Title = "Attendance list",
    BindingContext = vm
});

`

And it works. I can go to tabbed page and children content pages. The problem is when I clicking back button of tabbed page(this previous page arrow :)).
First click resets the tabbedpage(I think it is recreated because my controls lost data) and then second click return to MainPage. Why?

Third question is about ViewModels. As you saw in previous question I have tabbedPage with tabbedPageViewModel and two contentPages but I don't have view models for them. It's one domain context from my perspective. Should I use one ViewModel for one View? If yes then:

Fourth, how to send data, messages between ViewModels/Pages if not via constructor?
If PageOne creates PageTwo it's easy via constructor. But When PageTwo want send some data back to PageOne. How to do that?

I read something about MessaginCenter. Is this the key to this?

Last question, should I use MVVM framework for Xamarin Forms?
I have read on stackoverflow that you should not use it because XF already has it in itself.
How is it? What do you think about it?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>