public void TestBindingPath() { var xaml = @" <StackLayout xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> <StackLayout.Children> <Label x:Name=""label0"" Text=""{Binding text}""/> <Label x:Name=""label1"" Text=""{Binding Path=text}""/> </StackLayout.Children> </StackLayout>" ; var stacklayout = new StackLayout(); stacklayout.LoadFromXaml(xaml); var label0 = stacklayout.FindByName <Label> ("label0"); var label1 = stacklayout.FindByName <Label> ("label1"); Assert.AreEqual(Label.TextProperty.DefaultValue, label0.Text); Assert.AreEqual(Label.TextProperty.DefaultValue, label1.Text); stacklayout.BindingContext = new { text = "Foo" }; Assert.AreEqual("Foo", label0.Text); Assert.AreEqual("Foo", label1.Text); }
private async void RejectButton_Clicked(object sender, EventArgs e) { //Comments are REQUIRED to be submitted at rejection //To Be Done : Implement content validation of Comments Content to ensure users aren't sending null/whitespace/single character. Check if at least 15 characters are inputted. StackLayout commentsStack = CurrentPage.FindByName <StackLayout>("CommentsStack"); commentsStack.IsVisible = true; var commentsContent = commentsStack.FindByName <Editor>("CommentsEditor").Text; commentsStack.FindByName <Editor>("CommentsEditor").Focus(); if (string.IsNullOrEmpty(commentsContent) || string.IsNullOrWhiteSpace(commentsContent)) { await DisplayAlert("Comments Required", "Please enter a brief description of your reason for rejecting this application.", "OK"); } else { bool confirm = await DisplayAlert("Confirm", "Are you sure you want to reject this application?", "Yes", "No"); if (confirm) { int applicationid = int.Parse(viewModel.ReviewAppList[Children.IndexOf(CurrentPage)].applicationid); Comment comment = new Comment { applicationid = applicationid.ToString(), commenter = DataHandler.getEmployeeData().name, comment_by = "MANAGER", comment_time = DateTime.UtcNow, comment = commentsContent }; //Add Comment to Database //To be done : Implement feature for applicant to view comments on their HomePage as to why application was rejected CommentController.AddComment(comment); //Update Application Status to CANCELLED ApplicationController.RejectApplication(applicationid); //Once REJECTED, remove current application from ReviewAppList (list of applications to review that are visible to Manager) viewModel.ReviewAppList.RemoveAt(Children.IndexOf(CurrentPage)); if (viewModel.ReviewAppList.Count == 0) { HomePage.viewModel.ResetHomePageUI_OnNoApplicationstoReview(); } Navigation.PopAsync(); } } }
private async Task ChangeRankToOfficers(object e) { Rank = "Officer"; await FetchAllPersonsWithRank(Rank); StackLayout stack = (e as StackLayout); Button officers = stack.FindByName <Button>("BtnOfficers"); Button wofficers = stack.FindByName <Button>("BtnWOfficers"); Button soldiers = stack.FindByName <Button>("BtnSoldiers"); officers.IsEnabled = false; wofficers.IsEnabled = true; soldiers.IsEnabled = true; }
private async Task ChangeCategToFood(object e) { Category = "Food"; await FetchAllProductsWithCategory(Category); StackLayout stack = (e as StackLayout); Button food = stack.FindByName <Button>("BtnFood"); Button drinks = stack.FindByName <Button>("BtnDrinks"); Button snacks = stack.FindByName <Button>("BtnSnacks"); food.IsEnabled = false; drinks.IsEnabled = true; snacks.IsEnabled = true; }
private async Task ChangeCategToFood(object e) { Category = "Food"; changePurchasesContextAndSave(); StackLayout stack = (e as StackLayout); Button food = stack.FindByName <Button>("BtnFood"); Button drinks = stack.FindByName <Button>("BtnDrinks"); Button snacks = stack.FindByName <Button>("BtnSnacks"); food.IsEnabled = false; drinks.IsEnabled = true; snacks.IsEnabled = true; }
private async void TapGestureRecognizer_Tapped_1(object sender, EventArgs e) { if (!activeMV.UnTimeOfInspection.ISMaybiInspection) { await PopupNavigation.PushAsync(new AskHint(activeMV)); } else { if (SelectStackLayout != null) { SelectStackLayout.BackgroundColor = Color.White; SelectStackLayout = null; } string idOrder = null; StackLayout stackLayout = (StackLayout)sender; Label idorderL = stackLayout.FindByName <Label>("idOrder"); if (idorderL != null) { idOrder = idorderL.Text; } else { idOrder = stackLayout.Parent.Parent.FindByName <Label>("idOrder").Text; } await activeMV.Navigation.PushAsync(new InfoOrder(activeMV.managerDispatchMob, activeMV.initDasbordDelegate, activeMV.Shippings.Find(s => s.Id == idOrder).CurrentStatus, activeMV.Shippings.Find(s => s.Id == idOrder).Id)); } }
/// <summary> /// Hide validation message for input caller (it is recommended to set the FormBody element on Page initialization) /// </summary> protected virtual void HideErrorLabel(object sender, TextChangedEventArgs e) { if (sender is Entry entry) { if (FormBody == null) { FormBody = this.FindByName <StackLayout>("FormBody"); if (FormBody == null) { return; } } var labelToHide = FormBody.FindByName <Label>($"{entry.ClassId}Validation"); if (labelToHide != null) { labelToHide.Text = string.Empty; labelToHide.IsVisible = false; } } }
public void TestNonEmptyCollectionMembers() { var xaml = @" <StackLayout xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> <StackLayout.Children> <Grid x:Name=""grid0""> </Grid> <Grid x:Name=""grid1""> </Grid> </StackLayout.Children> </StackLayout>" ; var stacklayout = new StackLayout(); stacklayout.LoadFromXaml(xaml); var grid0 = stacklayout.FindByName <Grid> ("grid0"); var grid1 = stacklayout.FindByName <Grid> ("grid1"); Assert.NotNull(grid0); Assert.NotNull(grid1); }
protected async override void Invoke(Button sender) { StackLayout parentStack = sender.Parent.Parent as StackLayout; if (parentStack != null) { StackLayout searchLayout = parentStack.FindByName <StackLayout>("SearchForm"); if (searchLayout != null) { bool isHiding = (searchLayout.HeightRequest < 0 ? true : false); await PerformAnimation(isHiding, searchLayout, sender); } } }
public void TestFindByXName() { var xaml = @" <StackLayout xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> <StackLayout.Children> <Label x:Name=""label0"" Text=""Foo""/> </StackLayout.Children> </StackLayout>" ; var stacklayout = new StackLayout(); stacklayout.LoadFromXaml(xaml); var label = stacklayout.FindByName <Label> ("label0"); Assert.NotNull(label); Assert.AreEqual("Foo", label.Text); }
private void btnChangeText_Clicked(object sender, EventArgs e) { if ((int.Parse((sender as Button).ClassId.Replace("ClassID", "")) % 2) == 0) { #region 方法一:使用 Parent 屬性找出 StackLayout 物件,接著使用 FindByName 來搜尋 StackLayout stacklayout = ((sender as Button).Parent as StackLayout); Label label = stacklayout.FindByName <Label>("labelChange"); Console.WriteLine($"變更前的文字標籤的文字內容 : {label.Text}"); label.Text = "使用者已經按下按鈕"; Console.WriteLine($"變更後的文字標籤的文字內容 : {label.Text}"); #endregion } else { #region 使用 Reflection API,找出 ListView 的所有集合項目物件,接著透過 ClassId 來比對 string fooIndex = (sender as Button).ClassId.Replace("ClassID", "LabelClassID"); IEnumerable <PropertyInfo> pInfos = (lv as ItemsView <Cell>).GetType().GetRuntimeProperties(); var templatedItems = pInfos.FirstOrDefault(info => info.Name == "TemplatedItems"); if (templatedItems != null) { var cells = templatedItems.GetValue(lv); foreach (ViewCell cell in cells as Xamarin.Forms.ITemplatedItemsList <Xamarin.Forms.Cell> ) { StackLayout stacklayoutByClassId = cell.View as StackLayout; Label fooLabel = stacklayoutByClassId.Children.FirstOrDefault <Element>(x => x.ClassId == fooIndex) as Label; if (fooLabel == null) { continue; } Console.WriteLine($"@@變更前的文字標籤的文字內容 : {fooLabel.Text}"); fooLabel.Text = "@@使用者已經按下按鈕"; Console.WriteLine($"@@變更後的文字標籤的文字內容 : {fooLabel.Text}"); } } #endregion } }
private static void DisplayCalendar(Grid cal, StackLayout MonthSelect) { // Makes the buttons transparent if user is at the end of intended month intverval if (current.Month != 8) { MonthSelect.FindByName <Image>("PrevImg").Opacity = 1; } else { MonthSelect.FindByName <Image>("PrevImg").Opacity = 0.3; } if (current.Month != 6) { MonthSelect.FindByName <Image>("NextImg").Opacity = 1; } else { MonthSelect.FindByName <Image>("NextImg").Opacity = 0.3; } MonthSelect.FindByName <Label>("monthName").Text = Calendar.MonthToString(current.Month); MonthSelect.FindByName <Label>("year").Text = current.Year.ToString(); var calChildren = cal.Children; List <int> consecutiveDays = data.Calendar.GetCal(current); IEnumerator enumerator = calChildren.GetEnumerator(); int i = 0; List <School> favoriteSchoolsTrimmed = favoriteSchools; List <List <CalendarDay> > selectedSchoolsCalendars = new List <List <CalendarDay> >(); if (favoriteSchoolsTrimmed != null && favoriteSchoolsTrimmed.Count > Constants.MaximumSelectedSchools) { favoriteSchoolsTrimmed = favoriteSchools.GetRange(0, Constants.MaximumSelectedSchools); } // TODO: Change from favorite schools to selected schools to enable the user to choose schools to be displayed if (favoriteSchoolsTrimmed != null && favoriteSchoolsTrimmed.Count > 0) { foreach (School selected in favoriteSchoolsTrimmed) { selectedSchoolsCalendars.Add(data.Calendar.GetRelevantFreeDays(selected.calendar, current)); } } while (enumerator.MoveNext()) { try { StackLayout sl = enumerator.Current as StackLayout; Label label = sl.Children.First() as Label; StackLayout boxes = sl.Children.Last() as StackLayout; label.Text = consecutiveDays.ElementAt(i).ToString(); if (selectedSchoolsCalendars.Count > 0 && favoriteSchoolsTrimmed != null) { for (int j = 0; j < selectedSchoolsCalendars.Count && j < favoriteSchoolsTrimmed.Count; j++) { boxes.Children.ElementAt(j).IsVisible = true; boxes.Children.ElementAt(j).BackgroundColor = Constants.colors.ElementAt(j); if (selectedSchoolsCalendars.ElementAt(j).ElementAt(i).IsFreeDay&& ((int)selectedSchoolsCalendars.ElementAt(j).ElementAt(i).Date.DayOfWeek) % 6 != 0 && ((int)selectedSchoolsCalendars.ElementAt(j).ElementAt(i).Date.DayOfWeek) % 7 != 0) { boxes.Children.ElementAt(j).Opacity = 1.0; } else { boxes.Children.ElementAt(j).Opacity = 0.0; } } } i++; } catch (Exception e) { MonthSelect.FindByName <Label>("monthName").Text = string.Empty; } } }
public MainPageViewModel(INavigationService navigationService) : base(navigationService) { Title = "Main Page"; OpenFormCommand = new DelegateCommand(async() => { var fakeQuestion = JsonConvert.DeserializeObject <FormsModel>(FakeData.Questions); string xaml = $"{DynamicPage.Header}" + $"{CreateWidgets(fakeQuestion)}" + $"{DynamicPage.Footer}"; ContentPage page = new ContentPage().LoadFromXaml(xaml); StackLayout stackLayoutRoot = page.FindByName <StackLayout>("StackLayoutRoot"); foreach (var forms in fakeQuestion.AreasFormulario) { foreach (var question in forms.Questoes) { switch (question.TipoResposta) { case (int)ResponseTypes.CaixaSelecao: foreach (var answer in question.ListaRespostas) { var raddioButton = stackLayoutRoot.FindByName <RadioButton>($"{question.FormularioAreaId}_{question.Identificador}_{answer}"); raddioButton.Text = answer; } break; case (int)ResponseTypes.Decimal: if (!string.IsNullOrEmpty(question.ExpressaoCalculoMobile)) { var allWorlds = EverythingBetween(question.ExpressaoCalculoMobile, "[", "]").Distinct().ToList(); var allAnswers = new List <KeyValuePair <string, object> >(); var entryCalculable = stackLayoutRoot.FindByName <Entry>($"{question.FormularioAreaId}_{question.Identificador}"); entryCalculable.IsReadOnly = true; for (int i = 0; i < allWorlds.Count; i++) { var entryThatInsertsValue = stackLayoutRoot.FindByName <Entry>($"{question.FormularioAreaId}_{allWorlds[i]}"); entryThatInsertsValue.StyleId = $"{allWorlds[i]}"; // Este valor é adicionado na lista previamente para que cada campo tenha seu indice pre-definido e eu possa resgata-lo futuramente usando o index of. allAnswers.Add(new KeyValuePair <string, object>($"{allWorlds[i]}", null)); entryThatInsertsValue.TextChanged += (sender, args) => { try { var index = allAnswers.FindIndex(pair => pair.Key == entryThatInsertsValue.StyleId); allAnswers.RemoveAt(index); allAnswers.Insert(index, new KeyValuePair <string, object>($"{entryThatInsertsValue.StyleId}", args.NewTextValue)); if (allAnswers.All(pair => pair.Value != null)) { if (allAnswers.All(pair => pair.Value.ToString() != "")) { var answers = new object[allWorlds.Count]; for (int j = 0; j < allWorlds.Count; j++) { //Index referente a cada campo nescessário para o calculo do método. var newindex = allAnswers.FindIndex(pair => pair.Key == allWorlds[j]); answers.SetValue(decimal.Parse(allAnswers[newindex].Value.ToString()), j); } var calculationExpression = question.ExpressaoCalculoMobile.Replace("[", "").Replace("]", ""); //Substituição das palavras for (int j = 0; j < allWorlds.Count; j++) { //Procuro a palavra dentro da string e adiciono a pocição dela com @, o @ é necessário pro método entender a posição do item calculationExpression = calculationExpression.Replace($"{allWorlds[j]}", $"@{j}"); } entryCalculable.Text = DynamicExpression(answers, calculationExpression); } else { entryCalculable.Text = string.Empty; } } } catch (Exception e) { Console.WriteLine(e.Message); } }; } } break; } } } await Prism.PrismApplicationBase.Current.MainPage.Navigation.PushAsync(page); }); }
public static T FindControlByName <T>(StackLayout pStackLayout, string pNameToFind) where T : class { return(pStackLayout.FindByName <T>(pNameToFind)); }