Sysnet.TouchScreen/AppCode/BaseWindow.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Messaging;
namespace Sysnet.TouchScreen
{
/// <summary>
/// A base class for windows that use MVVM
/// </summary>
public class BaseWindow : Window
{
public BaseWindow()
{
// Standard message to close the window
Messenger.Default.Register<MsgClose>(this, MsgClose_Handler);
}
protected override void OnClosed(EventArgs e)
{
// Unregister the messages of the window and its view model.
// This is very important, because the messages live outside their recipient.
// If you register a message in the constructor of a window and you open the window twice
// without having unregistered its message, that message will be registered (and handled) twice!
Messenger.Default.Unregister(this);
Messenger.Default.Unregister(this.DataContext);
base.OnClosed(e);
}
#region Messages handlers
void MsgClose_Handler(MsgClose msg)
{
this.OnMsgClose(msg);
}
#endregion
protected virtual void OnMsgClose(MsgClose msg)
{
// Close the window only if the message comes from the DataContext of this window
if (msg.SenderViewModel == this.DataContext)
{
this.Close();
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
