using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Imaging;
using System.Windows.Shapes;
namespace PDF_Master.CustomControl
{
public enum ContentResult
{
Cancel,
MiddleCancel,
Ok
}
///
/// 图标类型
///
public enum IconType
{
Tip,
Ask,
Error,
None
}
///
/// AlertsMessage.xaml 的交互逻辑
/// 因为是纯UI的逻辑显示,所以没有再创建VM
///
public partial class AlertsMessage : Window
{
public ContentResult result = ContentResult.Cancel;
public bool isChecked = false;
private Window ownerWindow;
public AlertsMessage()
{
InitializeComponent();
if (App.Current.MainWindow != this)
{
ownerWindow = App.Current.MainWindow;
}
}
public void ShowAskAgainCheck()
{
ChbDonotAskAgain.Visibility = Visibility.Visible;
}
///
/// 两个按钮弹窗
///
public void HaveCheckBoxShow(string title, string content,string contentCheckBox, string cancelBtn, string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Content = cancelBtn;
OkBtn.Content = okBtn;
ChbDonotAskAgain.Content = contentCheckBox;
ChbDonotAskAgain.Visibility = Visibility.Visible;
if (ownerWindow != null)
{
this.Owner = ownerWindow;
ShowDialog();
}
}
///
/// 一个按钮弹窗
///
public void Show(string title, string content,string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Visibility = Visibility.Collapsed;
OkBtn.Content = okBtn;
this.Show();
}
///
/// 两个按钮弹窗
///
public void Show(string title,string content,string cancelBtn,string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Content = cancelBtn;
OkBtn.Content = okBtn;
this.Show();
}
///
/// 三个按钮弹窗
///
public void Show(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Visible;
CancelBtn.Content = cancelBtn1;
MiddleCancelBtn.Content = cancelBtn2;
OkBtn.Content = okBtn;
this.Show();
}
public void ShowDialog(string title, string content, string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Visibility = Visibility.Collapsed;
OkBtn.Content = okBtn;
if (ownerWindow != null)
{
Owner = ownerWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowDialog();
}
}
public void ShowDialog(string title, string content, string cancelBtn, string okBtn,IconType type = IconType.None)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Content = cancelBtn;
OkBtn.Content = okBtn;
ShowIcon(type);
if (ownerWindow != null)
{
Owner = ownerWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowDialog();
}
}
public void ShowDialog(string title, string content, string okBtn, IconType type = IconType.None)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Collapsed;
MiddleCancelBtn.Visibility = Visibility.Collapsed;
OkBtn.Content = okBtn;
ShowIcon(type);
if (ownerWindow != null)
{
Owner = ownerWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowDialog();
}
}
public void ShowDialog(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
{
TitleText.Text = title;
ContentText.Text = content;
CancelBtn.Visibility = Visibility.Visible;
CancelBtn.Content = cancelBtn1;
MiddleCancelBtn.Content = cancelBtn2;
OkBtn.Content = okBtn;
if (ownerWindow != null)
{
Owner = ownerWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowDialog();
}
}
private void ShowIcon(IconType type)
{
//先隐藏所有图标
ImgTips.Visibility = Visibility.Collapsed;
switch (type)
{
case IconType.Tip:
GridIcon.Visibility = Visibility.Visible;
ImgTips.Visibility = Visibility.Visible;
break;
case IconType.Ask:
break;
case IconType.Error:
break;
case IconType.None:
default:
GridIcon.Visibility = Visibility.Collapsed;
break;
}
}
private void CancelBtn_Click(object sender, RoutedEventArgs e)
{
result = ContentResult.Cancel;
Close();
}
private void MiddleCancelBtn_Click(object sender, RoutedEventArgs e)
{
result = ContentResult.MiddleCancel;
Close();
}
private void OkBtn_Click(object sender, RoutedEventArgs e)
{
result = ContentResult.Ok;
Close();
}
private void Border_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void ChbDonotAskAgain_Checked(object sender, RoutedEventArgs e)
{
if (IsLoaded)
{
isChecked = true;
}
}
private void ChbDonotAskAgain_Unchecked(object sender, RoutedEventArgs e)
{
if (IsLoaded)
{
isChecked = false;
}
}
}
}