HintDialog.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace AwInitilizer
  15. {
  16. /// <summary>
  17. /// Interaction logic for HintDialog.xaml
  18. /// </summary>
  19. public partial class HintDialog : Window
  20. {
  21. public static void ShowMessage(string msg)
  22. {
  23. var confirmString = Resx.AppResources.Confirm;
  24. var dialog = new HintDialog() { Title = "",Message = msg,BtnText= confirmString };
  25. try
  26. {
  27. dialog.Owner = Application.Current.MainWindow;
  28. }
  29. catch
  30. {
  31. }
  32. dialog.ShowDialog();
  33. }
  34. public string Message
  35. {
  36. get => (string) uxConentText.Text;
  37. set => uxConentText.Text = value;
  38. }
  39. public string BtnText
  40. {
  41. get => (string)uxBtnText.Content;
  42. set => uxBtnText.Content = value;
  43. }
  44. public string Caption
  45. {
  46. get => (string)uxTitle.Content;
  47. set => uxTitle.Content = value;
  48. }
  49. private string _ImgPath;
  50. public string ImgPath
  51. {
  52. get => _ImgPath;
  53. set
  54. {
  55. if(_ImgPath!=value)
  56. {
  57. _ImgPath = value;
  58. if(string.IsNullOrEmpty(_ImgPath))
  59. {
  60. uxImage.Visibility = Visibility.Collapsed;
  61. }
  62. else
  63. {
  64. uxImage.Visibility = Visibility.Visible;
  65. uxImage.Source = new BitmapImage(new Uri(_ImgPath)) { };
  66. }
  67. }
  68. }
  69. }
  70. public bool IsCancelAble
  71. {
  72. get => uxCancelContainer.Visibility == Visibility.Visible;
  73. set
  74. {
  75. uxCancelContainer.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
  76. }
  77. }
  78. public HintDialog()
  79. {
  80. InitializeComponent();
  81. }
  82. private void Button_Click(object sender, RoutedEventArgs e)
  83. {
  84. this.Close();
  85. }
  86. private static ImageSource GetBitMap(string imgpath)
  87. {
  88. try
  89. {
  90. BitmapImage bitmapImg = new BitmapImage();
  91. bitmapImg.BeginInit();
  92. bitmapImg.UriSource = new Uri(imgpath, UriKind.RelativeOrAbsolute);
  93. bitmapImg.CreateOptions = BitmapCreateOptions.IgnoreColorProfile | BitmapCreateOptions.IgnoreImageCache;
  94. bitmapImg.CacheOption = BitmapCacheOption.OnLoad;
  95. bitmapImg.EndInit();
  96. bitmapImg.Freeze();
  97. return bitmapImg;
  98. }
  99. catch (Exception e)
  100. {
  101. Console.WriteLine(e.Message);
  102. return null;
  103. }
  104. }
  105. }
  106. }