git_bsmd/ENI2/Controls/StatusWindowBase.cs

55 lines
1.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;
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(); };
};
}
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(..)
}
}
}