1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Runtime.InteropServices;
- using System.Windows;
- using System.Windows.Interop;
- using vCloud.GeneratePackages.Tool.ViewModels;
- using Vinno.IUS.Common.Log;
- namespace vCloud.GeneratePackages.Tool
- {
- public interface IDescriptionUpdater
- {
- /// <summary>
- /// Update Discription
- /// </summary>
- /// <param name="desc"></param>
- void Update(string desc, bool writeLogger = true);
- /// <summary>
- /// The event Update Discription
- /// </summary>
- event EventHandler<string> DescriptionUpdated;
- }
- public class DescriptionUpdater : IDescriptionUpdater
- {
- /// <summary>
- /// The event Update Discription
- /// </summary>
- public event EventHandler<string> DescriptionUpdated;
- /// <summary>
- /// Update Discription
- /// </summary>
- /// <param name="desc"></param>
- public void Update(string desc, bool writeLogger = true)
- {
- if (writeLogger)
- {
- Logger.WriteLineInfo(desc);
- }
- DescriptionUpdated.Invoke(this, desc);
- }
- }
- /// <summary>
- /// ModalActionWindow.xaml 的交互逻辑
- /// </summary>
- public partial class ModalActionWindow : Window
- {
- ModalActionViewModel _viewModel;
- private const int GWL_STYLE = -16;
- private const int WS_SYSMENU = 0x80000;
- [DllImport("user32.dll", SetLastError = true)]
- private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
- [DllImport("user32.dll")]
- private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
- public ModalActionWindow(Action action, IDescriptionUpdater descriptionUpdater, string descpription = null, string title = null)
- {
- InitializeComponent();
- Loaded += OnWindow_Loaded;
- _viewModel = new ModalActionViewModel(action, descriptionUpdater, descpription, title);
- _viewModel.ClosedRequest += OnClose;
- DataContext = _viewModel;
- }
- private void OnWindow_Loaded(object sender, RoutedEventArgs e)
- {
- var hwnd = new WindowInteropHelper(this).Handle;
- SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
- }
- /// <summary>
- /// Update description
- /// </summary>
- /// <param name="desc"></param>
- public void Update(string desc)
- {
- Dispatcher.Invoke(()=> {
- if (_viewModel != null)
- {
- _viewModel.Description = desc;
- }
- });
- }
- private void OnClose(object sender, EventArgs e)
- {
- Loaded -= OnWindow_Loaded;
- _viewModel.ClosedRequest -= OnClose;
- Close();
- }
- }
- }
|