mvvm sample
This commit is contained in:
75
PacticeSolution/MVVMSample/Model/ViewModelMain.cs
Normal file
75
PacticeSolution/MVVMSample/Model/ViewModelMain.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MVVMSample.Model
|
||||
{
|
||||
internal class ViewModelMain : NotifierMain
|
||||
{
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
private string _fullName;
|
||||
private string _birthday;
|
||||
|
||||
private bool _isBirthdayError = false;
|
||||
|
||||
public string FirstName
|
||||
{
|
||||
get { return _firstName; }
|
||||
set
|
||||
{
|
||||
_firstName = value;
|
||||
_fullName = $"{_lastName} {_firstName}";
|
||||
NotifyChanged("FirstName", "FullName");
|
||||
}
|
||||
}
|
||||
|
||||
public string LastName
|
||||
{
|
||||
get { return _lastName; }
|
||||
set
|
||||
{
|
||||
_lastName = value;
|
||||
_fullName = $"{_lastName} {_firstName}";
|
||||
NotifyChanged("LastName", "FullName");
|
||||
}
|
||||
}
|
||||
|
||||
public string FullName { get { return _fullName; } }
|
||||
|
||||
public string Birthday
|
||||
{
|
||||
get { return _birthday; }
|
||||
set
|
||||
{
|
||||
if (Regex.IsMatch(value, "^[0-9]*$"))
|
||||
{
|
||||
_birthday = value;
|
||||
_isBirthdayError = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_birthday = value;
|
||||
_isBirthdayError = true;
|
||||
}
|
||||
NotifyChanged("Birthday", "BirthdayError", "BirthdayErrorMessage");
|
||||
}
|
||||
}
|
||||
|
||||
public bool BirthdayError { get { return _isBirthdayError; } }
|
||||
|
||||
public string BirthdayErrorMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_isBirthdayError)
|
||||
return $"Birthday: {_birthday}";
|
||||
else
|
||||
return $"Please input the number value ({Birthday})";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user