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
///
/// Multicast event for property change notifications.
///
private PropertyChangedEventHandler _propertyChanged;
private readonly List events = new();
public new event PropertyChangedEventHandler PropertyChanged
{
add { _propertyChanged += value; events.Add("added"); }
remove { _propertyChanged -= value; events.Add("removed"); }
}
protected bool RaiseAndSetIfChanged(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(field, value)) return false;
field = value;
RaisePropertyChanged(propertyName);
return true;
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
}
///
/// Notifies listeners that a property value has changed.
///
///
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support .
///
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;
}
}
}