Files
elwig/WGneu/App.xaml.cs
2023-03-09 21:17:46 +01:00

45 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace WGneu {
public partial class App : Application {
public static bool IsPrintingReady => Documents.Html.IsReady && Documents.Pdf.IsReady;
public static System.Windows.Threading.Dispatcher MainDispatcher { get; private set; }
public App() : base() {
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
MainDispatcher = Dispatcher;
}
protected override void OnStartup(StartupEventArgs e) {
Task.Run(() => Documents.Html.Init(PrintingReadyChanged));
Task.Run(() => Documents.Pdf.Init(PrintingReadyChanged));
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e) {
Task.Run(() => Documents.Pdf.Close());
base.OnExit(e);
}
private void PrintingReadyChanged() {
Dispatcher.BeginInvoke(OnPrintingReadyChanged, new EventArgs());
}
protected void OnPrintingReadyChanged(EventArgs e) {
foreach (Window w in Windows) {
foreach (var b in Utils.FindVisualChilds<Button>(w).Where(b => "Print".Equals(b.Tag))) {
b.IsEnabled = IsPrintingReady;
}
}
}
}
}