Catalog/imagecatalog/ViewModelBase.cs
MaddoScientisto d6b778a648 Refactor application to remove Windows Forms dependencies and transition to Avalonia UI
- Deleted MainWindow.xaml.cs, which contained the WPF implementation of the main window.
- Updated Program.cs to remove Windows Forms initialization and support only Avalonia UI.
- Removed Windows Forms specific code from ViewModelBase, including control marshalling logic.
2026-05-09 14:04:21 +02:00

48 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ImageCatalog_2
{
public class ViewModelBase : INotifyPropertyChanged
{
private readonly SynchronizationContext? _synchronizationContext;
protected ViewModelBase()
{
// Capture the synchronization context (UI thread context)
_synchronizationContext = SynchronizationContext.Current;
}
public event PropertyChangedEventHandler? PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
protected void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged == null)
return;
if (_synchronizationContext != null && SynchronizationContext.Current != _synchronizationContext)
{
// We're on a different thread, marshal to the UI thread
_synchronizationContext.Send(_ =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}, null);
}
else
{
// We're already on the UI thread or no sync context available
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}