Files
UVtools/UVtools.WPF/Controls/UserControlEx.cs
T
Tiago Conceição edd9984a31 v2.11.2
- (Improvement) Applied some refactorings on code
- (Fix) MDLP, GR1 and CXDLP: Bad enconde of display width, display height and layer height properties
2021-05-13 03:24:36 +01:00

62 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Controls;
using UVtools.Core.FileFormats;
namespace UVtools.WPF.Controls
{
public class UserControlEx : UserControl, INotifyPropertyChanged
{
#region BindableBase
/// <summary>
/// Multicast event for property change notifications.
/// </summary>
private PropertyChangedEventHandler _propertyChanged;
private readonly List<string> events = new();
public new event PropertyChangedEventHandler PropertyChanged
{
add { _propertyChanged += value; events.Add("added"); }
remove { _propertyChanged -= value; events.Add("removed"); }
}
protected bool RaiseAndSetIfChanged<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
RaisePropertyChanged(propertyName);
return true;
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
}
/// <summary>
/// Notifies listeners that a property value has changed.
/// </summary>
/// <param name="propertyName">
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support <see cref="CallerMemberNameAttribute" />.
/// </param>
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
var e = new PropertyChangedEventArgs(propertyName);
OnPropertyChanged(e);
_propertyChanged?.Invoke(this, e);
}
#endregion
public FileFormat SlicerFile => App.SlicerFile;
public void ResetDataContext()
{
var old = DataContext;
DataContext = new object();
DataContext = old;
}
}
}