using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interop;
using GummingCommon;
namespace GummingCommon
{
///
/// BaseWindow is base class,many windows will inherit it.
/// this class automatic to adjust window size
///
public partial class BaseDialog : Window
{
public BaseDialog()
{
this.WindowStyle = WindowStyle.None;
this.ResizeMode = System.Windows.ResizeMode.NoResize;
this.WindowState = System.Windows.WindowState.Normal;
this.BorderThickness = new Thickness(0);
this.AllowsTransparency = true;
this.ShowInTaskbar = false;
//ScreenControl.ChangeScreenRangeBehavior(this);
ScreenZoom.Topmargin = 40;
this.MouseDown += new MouseButtonEventHandler(Window_MouseDown);
this.MouseMove += new MouseEventHandler(Window_MouseMove);
this.KeyDown += MainWindow_KeyDown;
this.Loaded += BaseDialog_Loaded;
//Application.Current.Resources.MergedDictionaries.Clear();
//string packUri2 = @"/GummingCommon;component/Resources.xaml";
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri(packUri2, UriKind.Relative)) as ResourceDictionary);
}
MessageBoxServiceViewModule _vm = null;
private MessageBoxServiceViewModule GetCurrentMv()
{
if (null == _vm)
{
_vm = this.DataContext as MessageBoxServiceViewModule;
}
return _vm;
}
ViewModelBase _viewer = null;
private ViewModelBase GetCurrentViewer()
{
if (null == _viewer)
{
_viewer = this.DataContext as ViewModelBase;
}
return _viewer;
}
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ScreenZoom.SetMouseState(this, true, e);
}
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
ScreenZoom.SetMouseState(this, false, e);
}
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
//this.Close();
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
Helpering.LeaveDialogToBuffer(this);
if (Application.Current.MainWindow != null)
{
if (GetCurrentMv() != null && _vm.IsKeepInProcessVisibility)
{
return;
}
if (GetCurrentViewer() != null && _viewer.IsKeepInProcessVisibility)
{
return;
}
AppEventAggregator.GetEventAggregator().GetEvent().Publish(new NotifyEventParameter() { NotifyType = CallbackType.CloseDialogView });
//MainWindow wm = (MainWindow)Application.Current.MainWindow;
//wm.CloseDialogView();
}
}
private void BaseDialog_Loaded(object sender, RoutedEventArgs e)
{
if (Application.Current.MainWindow != null && (GetCurrentViewer() == null || !GetCurrentViewer().DisabledShowDialogView))
{
AppEventAggregator.GetEventAggregator().GetEvent().Publish(new NotifyEventParameter() { NotifyType = CallbackType.ShowDialogView });
//MainWindow wm = (MainWindow)Application.Current.MainWindow;
//wm.ShowDialogView();
}
Helpering.PushDialogToBuffer(this);
}
}
}