private void UIElement_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { base.OnMouseDown(e); var hit = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if (hit == null) { _curDragDropItem = null; return; } var grid = this._listBoxGrid; //.VisualTree.FirstChild; if (grid == null) { _curDragDropItem = null; return; } var gridPosition = grid.GetColumnRow(e.GetPosition(grid)); if (_curDragDropItem != null && this.DataContext is ApplicationConfigurationModeViewModel) { (this.DataContext as ApplicationConfigurationModeViewModel).ChangeDevicePositionNumber(_curDragDropItem, (long)(gridPosition.Y * ApplicationGlobalNames.WidgetListColumnCount + gridPosition.X)); } _curDragDropItem = null; //MessageBox.Show(string.Format("Grid location Row: {1} Column: {0}", gridPosition.X, gridPosition.Y)); }
public IConfigDeviceViewModel CreateConfigDeviceViewModel(IConfigLogicalDevice configLogicalDevice) { IConfigDeviceViewModel configDeviceViewModel = _container.Resolve <IConfigDeviceViewModel>(); configDeviceViewModel.Model = configLogicalDevice; return(configDeviceViewModel); }
private void OnDeleteCurrentDevice(IConfigDeviceViewModel currentDevice) { if (!OnCanDeleteCurrentDevice(this.CurrentDevice)) { this._interactionService .Interact(ApplicationInteractionProviders.WarningMessageBoxInteractionProvider, viewModel => { viewModel.ButtonType = MessageBoxButtonType.OK; viewModel.Title = "Команда не может быть выполнена"; viewModel.Message = "Устройство для удаления не выбрано"; }, viewModel => { }); return; } this._interactionService .Interact(ApplicationInteractionProviders.QuestionMessageBoxInteractionProvider, viewModel => { viewModel.Message = "Вы действительно хотите удалить устройство с именем \"" + currentDevice.DeviceName + "\"?"; viewModel.Title = "Вы уверены?"; }, viewModel => { if (viewModel.Result == MessageBoxResult.YES) { this.OnDeleteDevice(this.CurrentDevice); } }); }
private void EventSetter_OnHandler(object sender, MouseButtonEventArgs e) { var send = (sender as ListBoxItem); if (send == null) { return; } _curDragDropItem = send.DataContext as IConfigDeviceViewModel; base.OnMouseDown(e); }
private void OnEditDeviceCommand(IConfigDeviceViewModel currentDevice) { if (!OnCanEditCurrentDevice(this.CurrentDevice)) { this._interactionService .Interact(ApplicationInteractionProviders.WarningMessageBoxInteractionProvider, viewModel => { viewModel.ButtonType = MessageBoxButtonType.OK; viewModel.Title = "Команда не может быть выполнена"; viewModel.Message = "Устройство для редактирования не выбрано"; }, viewModel => { }); return; } this._interactionService .Interact(ApplicationInteractionProviders.CreateNewDeviceProvider, viewModel => { try { var editDeviceModel = (this.CurrentDevice.Model as IConfigLogicalDevice).ToDeviceModel(); var state = this._persistanceService.GetDriverPersistableContextAsync( Guid.Parse((currentDevice.Model as IConfigLogicalDevice).CreateMomento().State.RelatedDriverId)) .Result.GetDriverMomentoAsync().Result.State; editDeviceModel.TcpAddress = state.GetTcpAddress(); editDeviceModel.TcpPort = state.GetTcpPort(); viewModel.SetEditingContext(editDeviceModel, Devices.Select((model => model.DeviceName))); } catch (Exception e) { } } , viewModel => { if (!viewModel.IsCanceled) { if (viewModel.ResultedDeviceModel.DeviceFactoryTypeName == null) { return; } this.OnEditDevice(viewModel.ResultedDeviceModel); } } ); }
/// <summary> /// Изменяет расположение устройства и решает коллизии перемещения устройств /// </summary> /// <param name="device">перемещаемое устройство</param> /// <param name="newPosition">новая позиция устройства</param> public void ChangeDevicePositionNumber(IConfigDeviceViewModel device, long newPosition) { var repeatPositionDevice = this.Devices.FirstOrDefault(dev => dev.DeviceNumber.Equals((int)newPosition)); if (repeatPositionDevice != null) { repeatPositionDevice.DeviceNumber = device.DeviceNumber; } if (device.DeviceNumber == (int)newPosition) { return; } device.DeviceNumber = (int)newPosition; SaveNewWidgetPosition(); }
private void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { var send = (sender as ListBoxItem); if (send == null) { return; } IConfigDeviceViewModel editingLogicalDevice = send.DataContext as IConfigDeviceViewModel; if (editingLogicalDevice != null && this.DataContext is ApplicationConfigurationModeViewModel) { (this.DataContext as ApplicationConfigurationModeViewModel).EditCurrentDeviceCommand?.Execute(editingLogicalDevice); } }
private async void OnDeleteDevice(IConfigDeviceViewModel deviceModel) { var busyToken = this.InteractWithBusy(); try { await this._configService.RemoveDeviceAsync(deviceModel.Model as IConfigLogicalDevice); this.Devices.Remove(deviceModel); } catch (Exception error) { busyToken.Dispose(); this.InteractWithError(error); } busyToken.Dispose(); }
private bool OnCanDeleteCurrentDevice(IConfigDeviceViewModel currentDevice) { return(currentDevice != null); }