??? MVVM ????? ??? ???? ?? ????? ???????
Tomer Kedem
Team Leader Full Stack | AI | C# | .NET | JavaScript | Angular | SQL | CI/CD
MVVM (Model-View-ViewModel) ??? ???? ????? ?????????? (Design Pattern) ?????? ?????? ??????? ?? ???? ????? ???? (GUI). ???? ?? ???? ?????? ??????????? ??????? XAML ??? WPF (Windows Presentation Foundation), Silverlight, ?-Xamarin, ??? ????????? Blazor ?? .NET.
??? ???? ????? (Design Pattern)?
???? ????? ??? ????? ???? ????? ????? ?????? ?????. ????? ?????? ?? ?????? ????? ??? ?????? ??????? ?????? ????? ???????? ?????? ?????. ????? ????? ??????? ??????? ????? ??? ???, ????? ??? ???????.
??? MVVM?
MVVM ??? ???? ????? ?????? ??? ??????? ?????? ?? ?????? (Model), ???? ?????? (View) ??????? ?????? (ViewModel). ????? ?? ?????? ????? ??? ????? ????? ????, ????? ??????? ?????? ????? ????? ????.
?????? ?-MVVM:
??????? ?????? ?-MVVM:
????? ?????? ?-MVVM:
???? (Model):
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
????-????? (ViewModel):
public class PersonViewModel : INotifyPropertyChanged
{
private Person _person;
public string FirstName
{
get { return _person.FirstName; }
set
{
_person.FirstName = value;
OnPropertyChanged(nameof(FirstName));
}
}
public string LastName
{
get { return _person.LastName; }
set
{
_person.LastName = value;
OnPropertyChanged(nameof(LastName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
????? (View):
<Window x:Class="MVVMExample.MainWindow"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<TextBox Text="{Binding FirstName, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding LastName, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</Window>
?????
MVVM ??? ???? ????? ?????????? ?????? ?????? ??? ??????? ??????, ???? ?????? ??????? ??????. ????? ?? ?????? ????? ?????, ????? ??????? ??????? ????? ???? ????. ???? ?? ???? ?????? ???????? ?????? XAML ??? WPF, Silverlight, Xamarin ?-Blazor.
????? ????? ??? ?? ????? ????? ???????????? ?????? ?????? ?????? ???????? ???? ????? ??????? ??????!
#MVVM #DesignPattern #TomerKedemQuiz #WPF #Blazor