57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System;
|
|
using Avalonia.Controls;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using GazpromApp.Messages;
|
|
using GazpromApp.ViewModels;
|
|
|
|
namespace GazpromApp.Views;
|
|
|
|
public partial class EditEquipmentDialog : Window
|
|
{
|
|
public EditEquipmentDialog()
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (Design.IsDesignMode)
|
|
return;
|
|
|
|
// view image
|
|
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ViewImageMessage>(this, static (w, m) =>
|
|
{
|
|
var dialog = new ImageView
|
|
{
|
|
DataContext = m.Image
|
|
};
|
|
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
|
|
});
|
|
|
|
// error handling
|
|
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ErrorMessage>(this, static (w, m) =>
|
|
{
|
|
var dialog = new ErrorView
|
|
{
|
|
DataContext = m.Error
|
|
};
|
|
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
|
});
|
|
|
|
// complete editing equipment
|
|
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, EditEquipmentDone>(this, static (w, m) =>
|
|
{
|
|
w.Close(m.Equipment);
|
|
});
|
|
}
|
|
|
|
private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
|
|
{
|
|
if (DataContext is EditEquipmentDialogViewModel { IsClosed: false } vm)
|
|
vm.CancelEditCommand.Execute(this);
|
|
}
|
|
|
|
private void Window_OnClosed(object? sender, EventArgs e)
|
|
{
|
|
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
|
|
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
|
WeakReferenceMessenger.Default.Unregister<EditEquipmentDone>(this);
|
|
}
|
|
} |