238 lines
5.5 KiB
C#
238 lines
5.5 KiB
C#
using BeWo.ViewModel.View;
|
|
using DevExpress.Web.Internal.XmlProcessor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
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.Animation;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BeWo.View.Windows
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für AnimatedBeWoWindow.xaml
|
|
/// </summary>
|
|
public partial class AnimatedBeWoWindow : Window
|
|
{
|
|
private bool closeStoryBoardCompleted = false;
|
|
private bool closePopupStoryBoardCompleted = false;
|
|
private bool openPopupStoryBoardCompleted = false;
|
|
private bool isClosing = false;
|
|
private WaitLayer2 _WaitLayer;
|
|
|
|
private object _GroupBoxContent;
|
|
public object GroupBoxContent
|
|
{
|
|
get { return _GroupBoxContent; }
|
|
set
|
|
{
|
|
_GroupBoxContent = value;
|
|
rootGroupBox.Content = value;
|
|
}
|
|
}
|
|
|
|
public bool IsMaximizable = true;
|
|
|
|
public WindowViewModel ViewModel
|
|
{
|
|
get => DataContext as WindowViewModel;
|
|
set => DataContext = value;
|
|
}
|
|
|
|
public AnimatedBeWoWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => Close()));
|
|
|
|
StartWaiting();
|
|
|
|
if (BeWoApp.MainControl.CurrentAnimatedBeWoWindow == null)
|
|
{
|
|
BeWoApp.MainControl.CurrentAnimatedBeWoWindow = this;
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("Opening, BeWoApp.CurrentAnimatedBeWoWindow already set");
|
|
}
|
|
}
|
|
|
|
public AnimatedBeWoWindow(FrameworkElement fe) : this()
|
|
{
|
|
rootGroupBox.Content = fe;
|
|
}
|
|
|
|
public void Window_Closing(object sender, CancelEventArgs e)
|
|
{
|
|
if (!closeStoryBoardCompleted && !isClosing)
|
|
{
|
|
isClosing = true;
|
|
|
|
if (BeWoApp.MainControl.CurrentAnimatedBeWoWindow == this)
|
|
{
|
|
BeWoApp.MainControl.CurrentAnimatedBeWoWindow = null;
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("Closing, BeWoApp.CurrentAnimatedBeWoWindow not found");
|
|
}
|
|
|
|
if (FindResource("WindowClosingAnimation") is Storyboard storyboard)
|
|
{
|
|
storyboard.Completed += closeStoryBoard_Completed;
|
|
Storyboard.SetTarget(storyboard.Children[0], this);
|
|
Storyboard.SetTarget(storyboard.Children[1], this);
|
|
storyboard.Begin();
|
|
e.Cancel = true;
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("WindowClosingAnimation not found");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void closeStoryBoard_Completed(object sender, EventArgs e)
|
|
{
|
|
closeStoryBoardCompleted = true;
|
|
isClosing = false;
|
|
|
|
Close();
|
|
}
|
|
|
|
private void RootGroupBox_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var p = e.GetPosition(this);
|
|
if (p.Y <= 40)
|
|
{
|
|
DragMove();
|
|
}
|
|
}
|
|
catch (Exception) { }
|
|
}
|
|
|
|
private void RootGroupBox_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (!IsVisible)
|
|
{
|
|
return;
|
|
}
|
|
if (!IsMaximizable)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var pos = PointToScreen(Mouse.GetPosition(this));
|
|
|
|
if (!(e.OriginalSource is Border) && !(e.OriginalSource is TextBlock) || pos.Y > 200d || e.OriginalSource is TextBlock && Mouse.DirectlyOver is Button)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (WindowState == WindowState.Maximized)
|
|
{
|
|
WindowState = WindowState.Normal;
|
|
return;
|
|
}
|
|
|
|
if (WindowState == WindowState.Normal)
|
|
{
|
|
WindowState = WindowState.Maximized;
|
|
}
|
|
}
|
|
|
|
public void Window_Closed(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public void StartWaiting()
|
|
{
|
|
if (openPopupStoryBoardCompleted)
|
|
return;
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)delegate
|
|
{
|
|
if (FindResource("PopupLoadedAnimation") is Storyboard storyboard)
|
|
{
|
|
openPopupStoryBoardCompleted = true;
|
|
StartWaitingImmediately();
|
|
storyboard.Completed += openPopupStoryBoard_Completed;
|
|
Storyboard.SetTarget(storyboard.Children[0], _WaitingLayer);
|
|
Storyboard.SetTarget(storyboard.Children[1], _WaitingLayer);
|
|
storyboard.Begin();
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("PopupLoadedAnimation not found");
|
|
}
|
|
});
|
|
}
|
|
|
|
private void openPopupStoryBoard_Completed(object sender, EventArgs e)
|
|
{
|
|
if (!openPopupStoryBoardCompleted)
|
|
return;
|
|
|
|
openPopupStoryBoardCompleted = false;
|
|
}
|
|
|
|
public void StartWaitingImmediately()
|
|
{
|
|
ViewModel.IsWaiting = true;
|
|
Keyboard.Focus(_WaitingLayer);
|
|
_WaitingLayer.Focus();
|
|
}
|
|
|
|
public void EndWaiting()
|
|
{
|
|
if (closePopupStoryBoardCompleted)
|
|
return;
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate
|
|
{
|
|
if (FindResource("PopupClosingAnimation") is Storyboard storyboard)
|
|
{
|
|
closePopupStoryBoardCompleted = true;
|
|
storyboard.Completed += closePopupStoryBoard_Completed;
|
|
Storyboard.SetTarget(storyboard.Children[0], _WaitingLayer);
|
|
Storyboard.SetTarget(storyboard.Children[1], _WaitingLayer);
|
|
storyboard.Begin();
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("PopupClosingAnimation not found");
|
|
}
|
|
});
|
|
}
|
|
|
|
private void closePopupStoryBoard_Completed(object sender, EventArgs e)
|
|
{
|
|
if (!closePopupStoryBoardCompleted)
|
|
return;
|
|
|
|
closePopupStoryBoardCompleted = false;
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)EndWaitingImmediately);
|
|
}
|
|
|
|
public void EndWaitingImmediately()
|
|
{
|
|
ViewModel.IsWaiting = false;
|
|
}
|
|
}
|
|
}
|