194 lines
6.6 KiB
C#
194 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
|
|
namespace Xylem.Common.Production.ProductionUiCordonel.UserControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for UcDialog.xaml
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public partial class UcDialog : IUserControl
|
|
{
|
|
/// <summary>
|
|
/// Error dialog will use a different color for background and text.
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
/// <remarks date="2024-Aug-30" author="Thomas Wiedebusch">
|
|
/// - Fixed button size
|
|
/// </remarks>
|
|
public UcDialog(Boolean isErrorDialog = false)
|
|
{
|
|
InitializeComponent();
|
|
if (!isErrorDialog)
|
|
return;
|
|
|
|
Background = Brushes.Red;
|
|
lblHeadLine.Foreground = Brushes.White;
|
|
tbxMessage.Foreground = Brushes.White;
|
|
}
|
|
|
|
///<inheritdoc/>
|
|
public void Clear()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dialog inputs
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
/// <remarks date="2024-Aug-30" author="Thomas Wiedebusch">
|
|
/// - Fixed button size
|
|
/// </remarks>
|
|
public class DialogOption
|
|
{
|
|
private readonly Action _selectedAction;
|
|
private readonly String _btnText;
|
|
private readonly String _message;
|
|
private readonly Boolean _isErrorMsg;
|
|
private readonly Boolean? _isPositiveAcknBtn;
|
|
|
|
public DialogOption(String btnText, String message, Action selectedAction, Boolean isErrorMsg = false,
|
|
Boolean? isPositiveAcknBtn = null)
|
|
{
|
|
_btnText = btnText;
|
|
_message = message;
|
|
_selectedAction = selectedAction;
|
|
_isErrorMsg = isErrorMsg;
|
|
_isPositiveAcknBtn = isPositiveAcknBtn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Button generation
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
/// <remarks date="2024-Sep-02" author="Thomas Wiedebusch">
|
|
/// - Format changed to constant size, wrapping and coloring.
|
|
/// </remarks>
|
|
public UIElement GenerateBtn()
|
|
{
|
|
var backGroundColor = Brushes.White;
|
|
if (_isPositiveAcknBtn == null) {}
|
|
else if ((Boolean)_isPositiveAcknBtn) backGroundColor = Brushes.Aquamarine;
|
|
else backGroundColor = Brushes.LightPink;
|
|
|
|
var btn = new Button
|
|
{
|
|
Height = 52,
|
|
Width = 96,
|
|
Margin = new Thickness
|
|
{
|
|
Left = 4,
|
|
Right = 2,
|
|
Top = 4,
|
|
Bottom = 4
|
|
},
|
|
Background = backGroundColor,
|
|
Content = new TextBlock
|
|
{
|
|
Text = _btnText,
|
|
TextAlignment = TextAlignment.Center,
|
|
TextWrapping = TextWrapping.WrapWithOverflow
|
|
}
|
|
};
|
|
|
|
btn.Click += (sender, args) => { _selectedAction.Invoke(); };
|
|
return btn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Additional information for user right beside the button
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
/// <remarks date="2024-Sep-02" author="Thomas Wiedebusch">
|
|
/// - Format changed to constant size, wrapping and coloring.
|
|
/// </remarks>
|
|
public UIElement GenerateInfo()
|
|
{
|
|
var lbl = new TextBlock
|
|
{
|
|
Height = 52,
|
|
Width = 170,
|
|
Margin = new Thickness
|
|
{
|
|
Left = 4,
|
|
Right = 2,
|
|
Top = 4,
|
|
Bottom = 4
|
|
},
|
|
Text = _message,
|
|
HorizontalAlignment = HorizontalAlignment.Left,
|
|
TextWrapping = TextWrapping.WrapWithOverflow,
|
|
Foreground = _isErrorMsg ? Brushes.White : Brushes.Black
|
|
};
|
|
return lbl;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Interaction logic for UcDialog.xaml
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
internal void SetMessage(String message)
|
|
{
|
|
tbxMessage.Dispatcher.Invoke(DispatcherPriority.Send,
|
|
new Action(() => { tbxMessage.Text = message; }));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Interaction logic for UcDialog.xaml
|
|
/// </summary>
|
|
/// <remarks date="2024-Aug-31" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
internal void SetHeadline(String message)
|
|
{
|
|
lblHeadLine.Dispatcher.Invoke(DispatcherPriority.Send,
|
|
new Action(() => { lblHeadLine.Content = message; }));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set all elements containing a button and a text behind as extended user information.
|
|
/// </summary>
|
|
/// <remarks date="2020-Dec-12" author="Roland Drabesch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public void SetDialogOptions(List<DialogOption> optList)
|
|
{
|
|
stkPanel.Dispatcher.Invoke(DispatcherPriority.Send,
|
|
new Action(() => { stkPanel.Children.Clear(); }));
|
|
|
|
foreach (var opt in optList)
|
|
{
|
|
Dispatcher.Invoke(DispatcherPriority.Send,
|
|
new Action(() =>
|
|
{
|
|
var stackPnl = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal
|
|
};
|
|
stackPnl.Children.Add(opt.GenerateBtn());
|
|
stackPnl.Children.Add(opt.GenerateInfo());
|
|
stkPanel.Children.Add(stackPnl);
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|