## MVVM

Базовая реализация:

## INotifyPropertyChanged
```cs
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _sampleProperty1;
public string SampleProperty1
{
get => _sampleProperty1;
set
{
_sampleProperty1 = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SampleProperty1"));
}
}
private int _sampleProperty2;
public int SampleProperty2
{
get => _sampleProperty2;
set
{
_sampleProperty2 = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("_sampleProperty2"));
}
}
}
```
```cs
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private string _sampleProperty1;
public string SampleProperty1
{
get => _sampleProperty1;
set
{
if (Equals(_sampleProperty1, value)) return;
_sampleProperty1 = value;
RaisePropertyChanged(nameof(SampleProperty1));
}
}
private int _sampleProperty2;
public int SampleProperty2
{
get => _sampleProperty2;
set
{
if (Equals(_sampleProperty2, value)) return;
_sampleProperty2 = value;
RaisePropertyChanged(nameof(SampleProperty2));
}
}
}
```
```cs
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private string _sampleProperty1;
public string SampleProperty1
{
get => _sampleProperty1;
set
{
if (Equals(_sampleProperty1, value)) return;
_sampleProperty1 = value;
RaisePropertyChanged();
}
}
private int _sampleProperty2;
public int SampleProperty2
{
get => _sampleProperty2;
set
{
if (Equals(_sampleProperty2, value)) return;
_sampleProperty2 = value;
RaisePropertyChanged();
}
}
}
```
```cs
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class BindableBase : INotifyPropertyChanged
{
///
/// Multicast event for property change notifications.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
///
/// Type of the property.
/// Reference to a property with both getter and setter.
/// Desired value for the property.
///
/// Name of the property used to notify listeners. This value is optional and can be provided automatically when invoked from compilers that support CallerMemberName.
///
///
/// True if the value was changed, false if the existing value matched the desired value.
///
public bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Equals(storage, value)) return false;
storage = value;
RaisePropertyChanged(propertyName);
return true;
}
[NotifyPropertyChangedInvocator]
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
```
```cs
public class Bindable : BindableBase
{
private string _sampleProperty1;
public string SampleProperty1
{
get => _sampleProperty1;
set => SetProperty(ref _sampleProperty1, value);
}
private int _sampleProperty2;
public int SampleProperty2
{
get => _sampleProperty2;
set => SetProperty(ref _sampleProperty2, value);
}
}
```

## PRISM

## WPF NET CORE
XAML → CODE BEHIND → DICTIONARY → USER CONTROL→ CUSTOM CONTROL
## XAML
```xml
```
#### XAML конструктор

## CODE BEHIND
```cs
using System.Windows;
namespace DataMiner.View
{
///
/// Логика взаимодействия для MainWindow.xaml
///
public partial class StartView : Window
{
public StartView()
{
InitializeComponent();
}
}
}
```
## Словари ресурсов
```xml
…
```
## UserControl
```xml
```
## CustomControl
```cs
///
///
///
public class Connector : Control
{
#region ctor
static Connector()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Connector), new FrameworkPropertyMetadata(typeof(Connector)));
}
#endregion
}
```
## DependencyProperty
```cs
#region ConnectorOrientation DependencyProperty
///
///
///
public ConnectorOrientation ConnectorOrientation
{
get => (ConnectorOrientation)GetValue(ConnectorOrientationProperty);
set => SetValue(ConnectorOrientationProperty, value);
}
///
///
///
public static readonly DependencyProperty ConnectorOrientationProperty = DependencyProperty.Register(nameof(ConnectorOrientation), typeof(ConnectorOrientation), typeof(Connector));
#endregion
```
## Themes\Generic.xaml
```xml
```