public StackLayout GetMultiOptionsLayout(INavigation iNavigation, string currQuestionIndex) { this._Questions = QuestionJsonDeserializer.GetQuestion(currQuestionIndex); _baseLayer = new StackLayout(); _lableLayer = new StackLayout() { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(100, 10, 100, 10) }; for (int i = 0; i < _Questions.OtherQuestions.Count; i++) { _optionLabel = new Label() { FontSize = 20, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center, BackgroundColor = Color.Purple, TextColor = Color.White, HeightRequest = 70, WidthRequest = 500, Margin = new Thickness(0, 5, 0, 5) }; GlobalModel.MultiOptionsLabelList.Add(_optionLabel); TapGestureRecognizer _tapGestureRecognizer = new TapGestureRecognizer(); _tapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, "OptionTappedCommand"); MultiOpsLabelModel _multiOpsLabelModel = new MultiOpsLabelModel(i.ToString(), _optionLabel); _tapGestureRecognizer.CommandParameter = _multiOpsLabelModel; _optionLabel.GestureRecognizers.Add(_tapGestureRecognizer); _lableLayer.Children.Add(_optionLabel); } _baseLayer.Children.Add(_lableLayer); return(_baseLayer); }
async Task OptionTapped(MultiOpsLabelModel multiOpsModel) { if (!_tapLocked) { _tapLocked = true; _canLoadNext = false; _canGoBack = false; _selectedValue = multiOpsModel.ID; Console.WriteLine("tapped :" + _selectedValue); foreach (var item in MultiOptionsLabelList) { if (item.Id == multiOpsModel.OptionLabel.Id) { item.Opacity = 1; } else { item.Opacity = 0.5; } } await multiOpsModel.OptionLabel.ScaleTo(2, 150); await multiOpsModel.OptionLabel.ScaleTo(1, 150); Device.StartTimer(TimeSpan.FromSeconds(GlobalModel.TimeSpan), () => { LoadNextPage(); //_tapLocked = false; return(false); }); } }
public StackLayout GetMultiSelectionsLayout(string currQuestionIndex) { this._Questions = QuestionJsonDeserializer.GetQuestion(currQuestionIndex); ////remove not applicable facilities //if(_Questions.OtherQuestions != null && _Questions.OtherQValuesNA != null) //{ // foreach (var item in _Questions.OtherQuestions) // { // if(_Questions.OtherQValuesNA.Contains(item.QOId)) // { // _Questions.OtherQuestions.Remove(item); // } // } //} _baseLayer = new StackLayout(); _lableLayer = new StackLayout() { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(100, 10, 100, 10) }; for (int i = 0; i < _Questions.OtherQuestions.Count; i++) { _checkboxlayer = new StackLayout() { Orientation = StackOrientation.Horizontal, HeightRequest = 70 }; _checkBoxImage = new Image() { Aspect = Aspect.AspectFit, Source = ImageSource.FromFile("Images/unchecked.png"), HeightRequest = 50 }; _optionLabel = new Label() { FontSize = 20, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center, BackgroundColor = Color.FromRgb(60, 0, 70), TextColor = Color.White, WidthRequest = 500, Margin = new Thickness(0, 5, 0, 5) }; //Hide not Applicable Options if (_Questions.OtherQuestions != null && _Questions.OtherQValuesNA != null) { if (_Questions.OtherQValuesNA.Contains(i.ToString())) { _optionLabel.IsVisible = false; _checkBoxImage.IsVisible = false; } } _checkboxlayer.Children.Add(_checkBoxImage); _checkboxlayer.Children.Add(_optionLabel); GlobalModel.MultiSelectionsLabelList.Add(_optionLabel); GlobalModel.MultiSelectionsIconlList.Add(_checkBoxImage); TapGestureRecognizer _tapGestureRecognizer = new TapGestureRecognizer(); _tapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, "OptionTappedCommand"); MultiOpsLabelModel _multiOpsLabelModel = new MultiOpsLabelModel(i.ToString(), _optionLabel, _checkBoxImage); _tapGestureRecognizer.CommandParameter = _multiOpsLabelModel; _optionLabel.GestureRecognizers.Add(_tapGestureRecognizer); _checkBoxImage.GestureRecognizers.Add(_tapGestureRecognizer); _lableLayer.Children.Add(_checkboxlayer); } _baseLayer.Children.Add(_lableLayer); return(_baseLayer); }
async Task OptionTapped(MultiOpsLabelModel multiOpsModel) { try { //set message _messageLabel.Text = "Please Tap on Next button to continue"; //_selectedValue = multiOpsModel.ID; //Console.WriteLine("tapped :" + _selectedValue); if (!_tapLocked) { _tapLocked = true; int iconSeq = 0; foreach (var item in MultiSelectionsLabelList) { if (item.Id == multiOpsModel.OptionLabel.Id) { if (item.BackgroundColor == Color.FromRgb(60, 0, 70)) { item.BackgroundColor = Color.Purple; MultiSelectionsImageList[iconSeq].Source = ImageSource.FromFile("Images/checked.png"); } else { item.BackgroundColor = Color.FromRgb(60, 0, 70); MultiSelectionsImageList[iconSeq].Source = ImageSource.FromFile("Images/unchecked.png"); } } iconSeq++; } await multiOpsModel.OptionLabel.ScaleTo(2, 150); await multiOpsModel.OptionLabel.ScaleTo(1, 150); string[] selectedOptionsArray = new string[MultiSelectionsLabelList.Count]; int x = 0; int loop = 0; foreach (var item in MultiSelectionsLabelList) { if (item.BackgroundColor == Color.Purple) { selectedOptionsArray[loop] = x.ToString(); loop++; } x++; } _selectedValue = null; if (string.IsNullOrEmpty(selectedOptionsArray[0])) { //set message CommonPropertySetter.SetMessageLabelText(_messageLabel, _Questions.Optional); } foreach (var item in selectedOptionsArray) { if (!string.IsNullOrEmpty(item)) { if (string.IsNullOrEmpty(_selectedValue)) { _selectedValue = item; } else { _selectedValue += "," + item; } } } } _tapLocked = false; } catch (Exception) { } }