Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class
- class User : INotifyPropertyChanged {
- private string _username;
- public string username {
- get { return _username; }
- set {
- if (_username != value) {
- _username = value;
- RaisePropertyChanged();
- }
- }
- }
- private string _password;
- public string password {
- get { return _password; }
- set {
- if (_password != value) {
- _password = value;
- RaisePropertyChanged();
- }
- }
- }
- #region Notify Property Changed Members
- public event PropertyChangedEventHandler PropertyChanged;
- private void RaisePropertyChanged([CallerMemberName] string propertyName = "") {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- #endregion
- }
- }
- viewModel
- class RegisterViewModel {
- public RegisterCommand RegisterCommand { get; set; }
- User User;
- public RegisterViewModel(User user) {
- RegisterCommand = new RegisterCommand(this);
- }
- internal void SendData(object data) {
- Application.Current.MainPage.Navigation.PushAsync(new Page1());
- }
- }
- }
- Register Command
- class RegisterCommand : ICommand {
- public RegisterViewModel RegisterViewModel { get; set; }
- public RegisterCommand(RegisterViewModel registerViewModel) {
- RegisterViewModel = registerViewModel;
- }
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter) {
- if (parameter != null) {
- return true;
- }
- return false;
- }
- public void Execute(object parameter) {
- RegisterViewModel.SendData(parameter);
- }
- }
- }
- MainPge.xaml
- <ContentPage.Resources>
- <model:User x:Key="model" />
- <vm:RegisterViewModel x:Key="RegisteVM" />
- </ContentPage.Resources>
- <StackLayout>
- <Entry Placeholder="Username"
- Text="{Binding username, Source={StaticResource model}}" />
- <Entry Placeholder="Password"
- Text="{Binding password, Source={StaticResource model}}"/>
- <Button BackgroundColor="DarkCyan" Command="{Binding RegisterCommand, Source={StaticResource RegisteVM}}" >
- <Button.CommandParameter>
- <model:User/>
- </Button.CommandParameter>
- </Button>
- </StackLayout>
- SecondPage
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:d="http://xamarin.com/schemas/2014/forms/design"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- x:Class="Question.View.Page1">
- <ContentPage.Content>
- <StackLayout>
- <Label Text="Welcome to Xamarin.Forms!"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="CenterAndExpand" />
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
Add Comment
Please, Sign In to add comment