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 { /// /// Update Discription /// /// void Update(string desc, bool writeLogger = true); /// /// The event Update Discription /// event EventHandler DescriptionUpdated; } public class DescriptionUpdater : IDescriptionUpdater { /// /// The event Update Discription /// public event EventHandler DescriptionUpdated; /// /// Update Discription /// /// public void Update(string desc, bool writeLogger = true) { if (writeLogger) { Logger.WriteLineInfo(desc); } DescriptionUpdated.Invoke(this, desc); } } /// /// ModalActionWindow.xaml 的交互逻辑 /// 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); } /// /// Update description /// /// 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(); } } }