/// <summary> /// Initializes question values /// </summary> /// <param name="name">Question name</param> /// <param name="top">Top position on parent canvas</param> /// <param name="left">Left position on parent canvas</param> /// <param name="width">Question's width</param> /// <param name="height">Question's height</param> private void InitializeValues(string name, double top, double left, double width, double height) { this.Bubbles = new ObservableCollection <BubbleViewModel>(); this.AnswersMapping = new ObservableCollection <string>(AnswersMappingHelper.GetAnswersMappings()); this.Name = name; this.Top = top; this.Left = left; this.Width = width; this.Height = height; this.AddCustomMappingCommand = new RelayCommand(x => this.OnAddCustomMapping()); }
/// <summary> /// Open window to add custom mapping /// </summary> private void OnAddCustomMapping() { new CustomMappingViewModel(); var newItem = AnswersMappingHelper.GetAnswersMappings() .FirstOrDefault(x => !this.AnswersMapping.Contains(x)); if (newItem != null) { this.AnswersMapping.Insert(0, newItem); this.SelectedMapping = newItem; } }
/// <summary> /// Updates bubble names according to selected mapping /// </summary> private void UpdateBubblesNames() { string[] answerValues = AnswersMappingHelper.GetMappingByKey(this.SelectedMapping); for (int i = 0, j = 0; i < this.Bubbles.Count; i++, j++) { if (answerValues.Length <= j) { j -= answerValues.Length; } this.Bubbles[i].Name = answerValues[j]; } }
/// <summary> /// Open window to add custom mapping /// </summary> private void OnAddCustomMapping() { CustomMappingViewModel vm = new CustomMappingViewModel(); if (!vm.CustomMappingAdded) { return; } this.OnPropertyChanged(nameof(this.AnswersMapping)); string newItem = AnswersMappingHelper.GetAnswersMappings() .FirstOrDefault(x => x.Equals(vm.CustomMappingName)); if (newItem != null) { this.SelectedMapping = newItem; } }
/// <summary> /// Applies changes and closes window /// </summary> private void OnOkCommand() { if (string.IsNullOrEmpty(this.CustomMappingName)) { // show error DialogManager.ShowErrorDialog("Mapping name cannot be empty!"); return; } if (AnswersMappingHelper.CheckMappingExists(this.CustomMappingName)) { // already exists, should be unique DialogManager.ShowErrorDialog("Mapping name already exists! Make sure mapping name is unique."); return; } string[] resArray = this.MappingValues.Select(x => x.StringValue).ToArray(); AnswersMappingHelper.AddCustomMapping(this.CustomMappingName, resArray); this.view.Close(); }