git_bsmd/ENI2/Controls/StatusWindowBase.cs
Daniel Schick 4bc142ffc6 Bugfix für gleichzeitiges Schließen / Ändern von Dialogen
..führt offenbar zu Placement Problemen (Timing). Für Error/Validation habe ich daher unterschiedliche Position genommen. Im
Grunde ist das aber immer noch ein gräßlicher Häck der von der Tatsache ablenkt, dass jedes Fenster seinen Position separat
gespeichert haben sollte.
2024-03-26 12:06:48 +01:00

81 lines
2.9 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: Dialog Basisklasse analog EditWindowBase. Hier allerdings mit optionalem "Refresh" Knopf und
// "Close" statt "OK" und "Cancel"
using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using ENI2.Util;
using System.Windows.Data;
namespace ENI2.Controls
{
[TemplatePart(Name = "buttonRefresh", Type = typeof(Button))]
[TemplatePart(Name = "buttonClose", Type = typeof(Button))]
public class StatusWindowBase : Window
{
public event Action CloseClicked;
public event Action RefreshClicked;
static StatusWindowBase()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(StatusWindowBase), new FrameworkPropertyMetadata(typeof(StatusWindowBase)));
}
public StatusWindowBase()
{
Loaded += (_, __) =>
{
var closeButton = (Button)Template.FindName("buttonClose", this);
var refreshButton = (Button)Template.FindName("buttonRefresh", this);
closeButton.Click += (s, e) => { if (this.IsModal()) DialogResult = true; CloseClicked?.Invoke(); this.Close(); };
refreshButton.Click += (s, e) => { RefreshClicked?.Invoke(); };
string topProperty = "W2Top";
string leftProperty = "W2Left";
if(this.GetType().Name == "ViolationListDialog")
{
topProperty = "W3Top";
leftProperty = "W3Left";
}
SettingBindingExtension stBinding = new SettingBindingExtension(topProperty);
this.SetBinding(Window.TopProperty, stBinding);
SettingBindingExtension slBinding = new SettingBindingExtension(leftProperty);
this.SetBinding (Window.LeftProperty, slBinding);
};
}
public bool RefreshVisible
{
get { var refreshButton = (Button)Template.FindName("buttonRefresh", this); return refreshButton.Visibility == Visibility.Visible; }
set { var refreshButton = (Button)Template.FindName("buttonRefresh", this); refreshButton.Visibility = value ? Visibility.Visible : Visibility.Hidden; }
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
// this.SetPlacement(..)
}
public void BringUp()
{
if (!IsVisible) this.Show();
if (WindowState == WindowState.Minimized)
WindowState = WindowState.Normal;
Activate();
Topmost = true; // k.a. ob dieser grauenhafte Hack notwendig ist..
Topmost = false;
System.Diagnostics.Trace.WriteLine("XXX");
}
}
}