public ExcelProjectWindow(WindowOperation operation) { InitializeComponent(); if (operation != WindowOperation.Add) { projectNO.IsReadOnly = true; GridFile.Visibility = Visibility.Collapsed; } switch (operation) { case WindowOperation.Add: btnConfirm.Content = "添加"; break; case WindowOperation.Update: btnConfirm.Content = "更新"; this.Title = "修改工程"; break; case WindowOperation.Delete: btnConfirm.Content = "删除"; this.Title = "删除工程"; break; default: break; } this.Operation = operation; }
public CarTypeWindow(WindowOperation operation) { InitializeComponent(); if (operation != WindowOperation.Add) { typeno.IsReadOnly = true; this.tempCarNo = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car.CarNO; } switch (operation) { case WindowOperation.Add: btnConfirm.Content = "添加"; break; case WindowOperation.Update: btnConfirm.Content = "更新"; this.Title = "修改车型"; break; case WindowOperation.Delete: btnConfirm.Content = "删除"; this.Title = "删除车型"; break; default: break; } this.Operation = operation; }
private void CommonShow(string name, IDialogParameters parameters, Action <IDialogResult> callback, bool isModel) { Window window = null; try { window = CreateDialogWindow(name); } catch (Exception ex) { throw new InvalidOperationException("Cannot get a window", ex); } DialogWindowEvents(window, callback); MvvmHelpers.ViewAndViewModelAction <IDialogAware>(window.DataContext, d => d.OnDialogOpened(parameters)); if (isModel) { window.Owner = WindowOperation.GetCurrentActivatedWindow(); window.ShowDialog(); } else { window.Show(); } }
public AddEditUserWindow(WindowOperation windowOperation, User user = null) //edit window { InitializeComponent(); InitializeWindow(windowOperation, user); //fill window with user information (if edit window) this.user = user; //save user information this.windowOperation = windowOperation; //save current operation }
public override void Send(string from, string to, WindowOperation stateToBeSet) { IAbstractWindow windowToBeChanged = (IAbstractWindow)_windows[to]; if (windowToBeChanged != null) { windowToBeChanged.ReceiveStateChangeRequest(from, stateToBeSet); } }
private WindowOperationEventData CreateOpData(WindowOperation op) { return(new WindowOperationEventData() { Operation = op, WindowObject = this, DataObject = Content }); }
public static void Show(string title, string message, MessageBoxType messageBoxType, PathGeometry logoPath = null) { MessageView.Title = title; MessageView.Message = message; MessageView.MessageBoxType = messageBoxType; MessageView.LogoPath = logoPath; if (MessageView is Window view) { view.Owner = WindowOperation.GetCurrentActivatedWindow(); view.Show(); } }
//fill window with user information private void InitializeWindow(WindowOperation windowOperation, User user) { if (windowOperation.Equals(WindowOperation.Edit)) //if window type is Edit { btnAddEdit.Content = "Edit"; //change AddEditButton Content btnDelete.Visibility = Visibility.Visible; //show delete button //save user information if (!ReferenceEquals(user, null)) { tbName.Text = user.Name; tbEmail.Text = user.Email; tbAge.Text = user.Age.ToString(); } } }
public static bool?ShowDialog(string title, string message, MessageBoxType messageBoxType, PathGeometry logoPath = null) { MessageView.Title = title; MessageView.Message = message; MessageView.MessageBoxType = messageBoxType; MessageView.LogoPath = logoPath; if (MessageView is Window view) { view.Owner = WindowOperation.GetCurrentActivatedWindow(); return(view.ShowDialog()); } else { return(null); } }
public void ReceiveStateChangeRequest(string from, WindowOperation stateToBeSet) { //switch(stateToBeSet) //{ // case WindowOperation.Hide: // //this.Hide(); // break; // case WindowOperation.Show: // //this.DataContext = loginVM; // //this.Show(); // break; // case WindowOperation.Close: // // this.Close(); // break; // default: // break; //} }
public void Show(string title, string message, MessageBoxType messageBoxType, Geometry logoPath = null, MessageButtonType messageButtonType = MessageButtonType.Default, string determineText = "是", string cancelText = "否", double button1Width = 60, double button2Width = 60) { if (MessageView is Window) { Window view = Activator.CreateInstance(MessageView.WindowType) as Window; MessageView = view as IMessageView; MessageView.Title = title; MessageView.Message = message; MessageView.MessageBoxType = messageBoxType; MessageView.LogoPath = logoPath; MessageView.MessageButtonType = messageButtonType; MessageView.DetermineText = determineText; MessageView.CancelText = cancelText; MessageView.Button1Width = button1Width; MessageView.Button2Width = button2Width; (MessageView as Window).Owner = WindowOperation.GetCurrentActivatedWindow(); (MessageView as Window).Show(); } }
} //操作类型 public ExFixtureWindow(WindowOperation operation) { InitializeComponent(); if (operation != WindowOperation.Add) { txtFixture.IsReadOnly = true; txtFixture.Visibility = Visibility.Visible; txtFixture.IsReadOnly = true; cmbFixtures.Visibility = Visibility.Collapsed; isInput.Visibility = Visibility.Collapsed; } else { txtFixture.Visibility = Visibility.Collapsed; } switch (operation) { case WindowOperation.Add: btnConfirm.Content = "添加"; break; case WindowOperation.Update: btnConfirm.Content = "更新"; this.Title = "修改工程"; this.templed = ledAddr.Text; break; case WindowOperation.Delete: btnConfirm.Content = "删除"; this.Title = "删除工程"; break; default: break; } this.Operation = operation; }
private void SetWorkArea() { Rect rc = SystemParameters.WorkArea; int width, height; WindowOperation.WindowsLocation location = WindowOperation.GetWindowsBarLocation(out width, out height); switch (location) { case WindowOperation.WindowsLocation.bottom: this.Left = 0; //设置位置 this.Top = 0; this.Width = rc.Width; this.Height = rc.Height; break; case WindowOperation.WindowsLocation.left: this.Left = width; this.Top = 0; this.Width = rc.Width; this.Height = rc.Height; break; case WindowOperation.WindowsLocation.right: this.Left = 0; //设置位置 this.Top = 0; this.Width = rc.Width; this.Height = rc.Height; break; case WindowOperation.WindowsLocation.top: this.Left = 0; this.Top = height; this.Width = rc.Width; this.Height = rc.Height; break; } this.MaxHeight = rc.Height; this.MaxWidth = rc.Width; }
private void WindowShow() { if (WindowType == null) { WindowType = ContainerExtension.GetWindowObject(WindowName); } var windowObj = Activator.CreateInstance(WindowType); var window = windowObj as Window; window.Closed += (s, e) => { // 获取 Return Value object returnValue = null; if (window.DataContext != null) { if (window.DataContext is IDialogResult dialogResult) { returnValue = dialogResult; } } // 先调用 Command(如果设置了),再调用方法(如果同样设置了) // TODO: 这里临时这样做,如果没有返回值,则在调用 After Close 系列方法时,传入 Parameter 参数 //if (returnValue == null) //{ // returnValue = Parameter; //} CommandAfterClose?.Execute(returnValue); // 再调用方法 if (!string.IsNullOrWhiteSpace(MethodAfterClose)) { MethodInfo method = null; // 如果没有指定 MethodOfTargetObject,则默认为 AssociatedObject 的 DataContext (通常是 ViewModel) if (MethodOfTargetObject == null && MethodOfTargetObject is FrameworkElement) { var dataContext = (MethodOfTargetObject as FrameworkElement).DataContext; if (dataContext != null) { method = dataContext.GetType().GetMethod(MethodAfterClose, BindingFlags.Public | BindingFlags.Instance); method?.Invoke(dataContext, returnValue != null ? new object[] { returnValue } : null); } } else { method = MethodOfTargetObject?.GetType().GetMethod(MethodAfterClose, BindingFlags.Public | BindingFlags.Instance); method?.Invoke(MethodOfTargetObject, returnValue != null ? new object[] { returnValue } : null); } } }; if (window.DataContext != null && window.DataContext is IDialogResult) { (window.DataContext as IDialogResult).Parameters = Parameter as IDialogParameters; } else { window.Tag = Parameter; } if (IsHandleWindow) { if (IsModal) { WindowHandleManagement.HandleShowDialogWindow(new IntPtr(1), window, true); } else { WindowHandleManagement.HandleShowWindow(new IntPtr(1), window, true); } } else { window.Owner = WindowOperation.GetCurrentActivatedWindow(); if (IsModal) { window.ShowDialog(); } else { window.Show(); } } }
public void SendStateChangeRequest(string from, string to, WindowOperation stateToBeSet) { LoginWindowInformator.Send(from, to, stateToBeSet); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { string name = (sender as MenuItem).Header.ToString(); WindowOperation operation = WindowOperation.Add; if (name.Contains("车型")) { CarProject car = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car; switch (name.Substring(0, 2)) { case "新建": cmbCType.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car = new CarProject(); operation = WindowOperation.Add; break; case "修改": if (car == null) { MessageBox.Show("请选择一个车型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (car == null) { MessageBox.Show("请选择一个车型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } CarTypeWindow carTypeWindow = new CarTypeWindow(operation); carTypeWindow.ShowDialog(); } else if (name.Contains("线束")) { WireType wire = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Wire; switch (name.Substring(0, 2)) { case "新建": partcmb.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Wire = new WireType(); operation = WindowOperation.Add; break; case "修改": if (wire == null) { MessageBox.Show("请选择一个线束!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (wire == null) { MessageBox.Show("请选择一个线束!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } WireWindow wireWindow = new WireWindow(operation); wireWindow.ShowDialog(); } else if (name.Contains("工程")) { ExcelProject project = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project; switch (name.Substring(0, 2)) { case "新建": projectcmb.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project = new ExcelProject(); operation = WindowOperation.Add; break; case "修改": if (project == null) { MessageBox.Show("请选择一个工程!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (project == null) { MessageBox.Show("请选择一个工程!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } ExcelProjectWindow excelProjectWindow = new ExcelProjectWindow(operation); excelProjectWindow.ShowDialog(); } else if (name.Contains("治具")) { FixtureBase fixture = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture; switch (name.Substring(0, 2)) { case "新建": cmbFixture.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project = new ExcelProject(); operation = WindowOperation.Add; break; case "修改": if (fixture == null) { MessageBox.Show("请选择一个治具!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (fixture == null) { MessageBox.Show("请选择一个治具!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } ExFixtureWindow fixtureWindow = new ExFixtureWindow(operation); fixtureWindow.ShowDialog(); } }
protected override async void Invoke(object parameter) { try { if (IsSingleton) { var targetWindow = Application.Current.Windows.OfType <Window>().FirstOrDefault(m => m.GetType() == WindowType); if (targetWindow != null) { targetWindow.Activate(); return; } } if (this.ChenckingFuncBeforeOpenning != null) { if (!ChenckingFuncBeforeOpenning()) { return; } } if (CommandBeforeOpen != null) { CommandBeforeOpen.Execute(null); } if (!string.IsNullOrWhiteSpace(MethodBeforeOpen)) { MethodInfo method = null; Task task = null; // 如果没有指定 MethodOfTargetObject,则默认为 AssociatedObject 的 DataContext (通常是 ViewModel) if (MethodOfTargetObject == null && MethodOfTargetObject is FrameworkElement) { var dataContext = (MethodOfTargetObject as FrameworkElement).DataContext; if (dataContext != null) { method = dataContext.GetType().GetMethod(MethodBeforeOpen, BindingFlags.Public | BindingFlags.Instance); task = (Task)method?.Invoke(dataContext, null); } } else { method = MethodOfTargetObject?.GetType().GetMethod(MethodBeforeOpen, BindingFlags.Public | BindingFlags.Instance); task = (Task)method?.Invoke(MethodOfTargetObject, null); } if (task != null) { await task; } } if (WindowType == null) { WindowType = ContainerExtension.GetWindowObject(WindowName); } var windowObj = Activator.CreateInstance(WindowType); var window = windowObj as Window; window.Closed += (s, e) => { // 获取 Return Value object returnValue = null; if (window.DataContext != null) { if (window.DataContext is IDialogResult dialogResult) { returnValue = dialogResult; } } // 先调用 Command(如果设置了),再调用方法(如果同样设置了) // TODO: 这里临时这样做,如果没有返回值,则在调用 After Close 系列方法时,传入 Parameter 参数 //if (returnValue == null) //{ // returnValue = Parameter; //} CommandAfterClose?.Execute(returnValue); // 再调用方法 if (!string.IsNullOrWhiteSpace(MethodAfterClose)) { MethodInfo method = null; // 如果没有指定 MethodOfTargetObject,则默认为 AssociatedObject 的 DataContext (通常是 ViewModel) if (MethodOfTargetObject == null && MethodOfTargetObject is FrameworkElement) { var dataContext = (MethodOfTargetObject as FrameworkElement).DataContext; if (dataContext != null) { method = dataContext.GetType().GetMethod(MethodAfterClose, BindingFlags.Public | BindingFlags.Instance); method?.Invoke(dataContext, returnValue != null ? new object[] { returnValue } : null); } } else { method = MethodOfTargetObject?.GetType().GetMethod(MethodAfterClose, BindingFlags.Public | BindingFlags.Instance); method?.Invoke(MethodOfTargetObject, returnValue != null ? new object[] { returnValue } : null); } } }; if (window.DataContext != null && window.DataContext is IDialogResult) { (window.DataContext as IDialogResult).Parameters = Parameter as IDialogParameters; } else { window.Tag = Parameter; } if (IsModal) { window.Owner = WindowOperation.GetCurrentActivatedWindow(); window.ShowDialog(); } else { window.Show(); } } catch (Exception ex) { throw ex; } }
public abstract void Send(string from, string to, WindowOperation stateToSet);