//============================================================================= public void StartOldApp() { MainWindow_ViewModel vm = new MainWindow_ViewModel(); // Check - is view model correct initialized. string strError = string.Empty; if (vm == null || vm.CurrentDocument == null || vm.CurrentDocument.RacksColumnsList == null || vm.CurrentDocument.RacksColumnsList.Count == 0 || vm.CurrentDocument.BeamsList == null || vm.CurrentDocument.BeamsList.Count == 0) { strError = "Error occurred during apllication initializing. Application will be closed."; } if (string.IsNullOrEmpty(strError)) { MainWindow mainWnd = new MainWindow(vm); mainWnd.Show(); } else { MessageBox.Show(strError, "Error"); } this.Close(); }
//============================================================================= private void CreateSheetButton_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } MainWindow_ViewModel mainVM = btn.DataContext as MainWindow_ViewModel; if (mainVM == null) { return; } DrawingDocument curDoc = mainVM.CurrentDocument; if (curDoc == null) { return; } WarehouseSheet curSheet = curDoc.CurrentSheet as WarehouseSheet; if (curSheet == null || curSheet.SingleSelectedGeometry == null) { return; } SheetGeometry sheetGeometry = curSheet.SingleSelectedGeometry as SheetGeometry; if (sheetGeometry == null) { return; } if (sheetGeometry.BoundSheet != null) { return; } DrawingSheet newSheet = new DrawingSheet(curDoc); if (newSheet != null) { newSheet.Set_Length((UInt32)Utils.GetWholeNumber(sheetGeometry.Length_X), false, false); newSheet.Set_Width((UInt32)Utils.GetWholeNumber(sheetGeometry.Length_Y), false, false); curDoc.AddSheet(newSheet, false); sheetGeometry.BoundSheet = newSheet; curDoc.MarkStateChanged(); } }
public MainWindow(MainWindow_ViewModel vm) { InitializeComponent(); SourceInitialized += OnSourceInitialized; m_VM = vm; m_VM.DlgHost = DlgHost; m_VM.DrawingControl = this.Drawing; this.DataContext = m_VM; // this.MouseLeftButtonDown += MainWindow_MouseLeftButtonDown; this.SizeChanged += MainWindow_SizeChanged; this.KeyDown += MainWindow_KeyDown; this.Loaded += MainWindow_Loaded; this.ContentRendered += MainWindow_ContentRendered; }
//============================================================================= private void GoToBoundSheetButton_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } MainWindow_ViewModel mainVM = btn.DataContext as MainWindow_ViewModel; if (mainVM == null) { return; } DrawingDocument curDoc = mainVM.CurrentDocument; if (curDoc == null) { return; } WarehouseSheet curSheet = curDoc.CurrentSheet as WarehouseSheet; if (curSheet == null || curSheet.SingleSelectedGeometry == null) { return; } SheetGeometry sheetGeometry = curSheet.SingleSelectedGeometry as SheetGeometry; if (sheetGeometry == null) { return; } if (sheetGeometry.BoundSheet == null) { return; } curDoc.CurrentSheet = sheetGeometry.BoundSheet; }
//============================================================================= private async void RackAccessoriesButton_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } MainWindow_ViewModel mainVM = btn.DataContext as MainWindow_ViewModel; if (mainVM == null) { return; } DrawingDocument curDoc = mainVM.CurrentDocument; if (curDoc == null) { return; } DrawingSheet curSheet = curDoc.CurrentSheet; if (curSheet == null) { return; } if (curSheet.SelectedGeometryCollection.Count != 1) { return; } Rack selectedRack = curSheet.SelectedGeometryCollection[0] as Rack; if (selectedRack == null) { return; } RackAccessories rackAcc = selectedRack.Accessories.Clone() as RackAccessories; if (rackAcc == null) { return; } RackAccessories_ViewModel vm = new RackAccessories_ViewModel(rackAcc); RackAccessoriesDialog rackAccDialog = new RackAccessoriesDialog(vm); //show the dialog // true - OK // false - CANCEL var result = await DialogHost.Show(rackAccDialog); if (result is bool && (bool)result) { selectedRack.Accessories = vm.Accessories; } }