Hello
I am trying to wrap my head around MVVM and Interfaces. It doesn't all make sense to me yet. In the app below I have 3 xaml ENTRY controls and the data from that control I want to pass to a list. I would very much appreciate if someone could give me some idea on how to code this problem correctly.
thank you in advance.
[StartPage.xaml]
<ContentPage.Content>
<StackLayout Margin="20">
<Entry Placeholder="First Name"></Entry>
<Entry Placeholder="Last Name" Text="{Binding LastName}"></Entry>
<Entry Placeholder="EmailAddress"></Entry>
<Button Text="Save"
Command="{Binding saveCommand}"></Button>
</StackLayout>
</ContentPage.Content>
[StartPage.xaml.cs]
using Interfaces.Model;
using Interfaces.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Interfaces.View
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class StartPage : ContentPage
{
public StartPage()
{
InitializeComponent();
BindingContext = new StartPageViewModel();
}
}
}
[IPeople.cs]
namespace Interfaces.Model
{
public interface IPeople
{
string EmailAddress { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
}
}
[People.cs]
using System;
using System.Collections.Generic;
using System.Text;
namespace Interfaces.Model
{
public class People : IPeople
{
private string _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
private string _lastName;
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
private string _emailAddress;
public string EmailAddress
{
get { return _emailAddress; }
set { _emailAddress = value; }
}
}
}
[StartPageViewModel.cs]
using Interfaces.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;
namespace Interfaces.ViewModel
{
public class StartPageViewModel
{
public ICommand saveCommand { get; set;}
public StartPageViewModel()
{
saveCommand = new Command(Save);
}
private void Save()
{
List<IPeople> person = People();
}
private static List<IPeople> People()
{
List<IPeople> output = new List<IPeople>();
// get data from xaml ENTRY control
return output;
}
}
}
