/// <summary> /// Bind the data with ContentView of Side Panel /// </summary> public void LoadAccordian() { AccordionItems = GetSampleData().ToObservableCollection(); AccordionContent = new StackLayout(); var vFirst = true; foreach (var vSingleItem in AccordionItems) { var vHeaderButton = new AccordionButton() { Text = vSingleItem.HeaderText, TextColor = vSingleItem.HeaderTextColor, BackgroundColor = vSingleItem.HeaderBackGroundColor }; var vAccordionContent = new ContentView() { Content = vSingleItem.ContentItems, IsVisible = false }; if (vFirst) { vHeaderButton.Expand = _FirstExpaned; vAccordionContent.IsVisible = _FirstExpaned; vFirst = false; } vHeaderButton.AssosiatedContent = vAccordionContent; vHeaderButton.Clicked += OnAccordionButtonClicked; AccordionContent.Children.Add(vHeaderButton); AccordionContent.Children.Add(vAccordionContent); } }
private async void AcBtn_Clicked(object sender, EventArgs e) { AccordionButton btn = (AccordionButton)sender; StackLayout f = btn.ContentFrame; await btn.RotateTo((btn.FrameOpen ? 0 : 180), 200, Easing.CubicInOut); if (btn.FrameOpen) { await Task.WhenAll(new List <Task> { f.FadeTo(0, 200, Easing.Linear) }); f.IsVisible = false; f.ForceLayout(); btn.FrameOpen = false; } else { f.IsVisible = true; //await Task.WhenAll(new List<Task> { f.LayoutTo(new Rectangle(f.Bounds.X, f.Bounds.Y, f.Bounds.Width, 300), 500, Easing.CubicOut)}); await Task.WhenAll(new List <Task> { f.FadeTo(1, 400, Easing.Linear) }); //f.Opacity = 1; btn.FrameOpen = true; } }
void OnAccordionButtonClicked (object sender, EventArgs args) { //get the target layout which you want to expand StackLayout temp = targetLayout; //get a vSenderButton for which vSenderButton's AssosiatedContent you want to expand //here I take targetBtnList[1] as a example, you can sepcify whatever you want to expand AccordionButton vSenderButton = targetBtnList[1]; foreach (var vChildItem in temp.Children) { if (vChildItem.GetType() == typeof(ContentView)) vChildItem.IsVisible = false; if (vChildItem.GetType () == typeof(AccordionButton)) { var vButton = (AccordionButton)vChildItem; if (vButton != vSenderButton) { vButton.Expand = false; } } } //var vSenderButton = (AccordionButton)sender; if (vSenderButton.Expand) { vSenderButton.Expand = false; } else vSenderButton.Expand = true; vSenderButton.AssosiatedContent.IsVisible = vSenderButton.Expand; //replace the vSenderButton in the targetBtnList to update its Expand property targetBtnList[1] = vSenderButton; }
public void DataBind() { var vMainLayout = new StackLayout (); btnList = new List<AccordionButton> { }; var vFirst = true; if (mDataSource != null) { foreach (var vSingleItem in mDataSource) { var vHeaderButton = new AccordionButton () { Text = vSingleItem.HeaderText, TextColor = vSingleItem.HeaderTextColor, BackgroundColor = vSingleItem.HeaderBackGroundColor }; var vAccordionContent = new ContentView () { Content = vSingleItem.ContentItems, IsVisible = false }; if (vFirst) { vHeaderButton.Expand = mFirstExpaned; vAccordionContent.IsVisible = mFirstExpaned; vFirst = false; } vHeaderButton.AssosiatedContent = vAccordionContent; vHeaderButton.Clicked += OnAccordionButtonClicked; vMainLayout.Children.Add (vHeaderButton); vMainLayout.Children.Add (vAccordionContent); //store your buttons to use in the expand function btnList.Add(vHeaderButton); } } mMainLayout = vMainLayout; Content = mMainLayout; }
public void DataBind() { mainLayout = new StackLayout(); var layout = new StackLayout(); var first = true; if (DataSource != null) { var title = ""; var titleLabel = new Label(); foreach (var singleItem in DataSource) { singleItem.ShowTitle = (singleItem.Title ?? "") != title; title = singleItem.Title ?? ""; if (singleItem.ShowTitle) { titleLabel = new Label() { Text = singleItem.Title ?? "", IsVisible = singleItem.ShowTitle, Style = singleItem.TitleStyle, HorizontalOptions = LayoutOptions.Center } } ; var headerButton = new AccordionButton() { Text = singleItem.HeaderText, Style = singleItem.HeaderStyle }; var accordionContent = new ContentView() { Content = singleItem.ContentItems, IsVisible = false }; if (first) { headerButton.Expand = firstExpaned; accordionContent.IsVisible = firstExpaned; first = false; } headerButton.AssosiatedContent = accordionContent; headerButton.Clicked += OnAccordionButtonClicked; layout.Children.Add(titleLabel); layout.Children.Add(headerButton); layout.Children.Add(accordionContent); } } mainLayout = layout; Content = mainLayout; } void OnAccordionButtonClicked(object sender, EventArgs args) { foreach (var childItem in mainLayout.Children) { if (childItem.GetType() == typeof(ContentView)) { childItem.IsVisible = false; } if (childItem.GetType() == typeof(AccordionButton)) { var button = (AccordionButton)childItem; button.Expand = false; } } var senderButton = (AccordionButton)sender; if (senderButton.Expand) { senderButton.Expand = false; } else { senderButton.Expand = true; } senderButton.AssosiatedContent.IsVisible = senderButton.Expand; } }
/************* Learning Path Cards ************* * * *****************************************************/ public async Task <bool> buildObjectiveCard(Objective obj, StackLayout container, string lpid, int count) { Grid layout; // overall card layout // // objective title // Label objectiveTitle = new Label { Margin = new Thickness(0, 0, 0, 0), Text = obj.Name, VerticalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, HeightRequest = 40, Style = (Style)Application.Current.Resources["headerStyle"] }; // container for the content in the card layout = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand, WidthRequest = Constants.deviceWidth, Margin = new Thickness(0, 10, 0, 0) }; layout.Padding = new Thickness(16, 0, 16, 0); layout.RowDefinitions.Add(new RowDefinition { Height = 40 }); layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); StackLayout cardBody = new StackLayout { Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(0), ClassId = "course_" + obj.id, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, IsVisible = (count > 1) ? false : true, Opacity = (count > 1) ? 0 : 100 }; // used to expand accordion AccordionButton AcBtn = new AccordionButton { Image = "chevron_down.png", Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(0, 0, 0, 0), WidthRequest = 20, HeightRequest = 20, BackgroundColor = Color.Transparent, BorderColor = Color.Transparent }; AcBtn.ContentFrame = cardBody; AcBtn.FrameOpen = false; AcBtn.Clicked += AcBtn_Clicked; StackLayout frameContainer = new StackLayout(); foreach (Activity act in obj.Activities.Activity) { // chart for each activity in the objective ChartView chartView = null; float perc_complete = 0; float perc_incomplete = 0; Models.Record courseRecord = await App.Database.GetCourseByID(act.CourseID); if (courseRecord == null) { Models.Record rec = new Models.Record(); rec.CourseID = act.CourseID; // find the course name rec.CourseName = act.Name; rec.Version = "1"; rec.CourseDescription = ""; rec.CompletionStatus = "Not Started"; rec.SuccessStatus = ""; rec.Score = ""; rec.Deleted = "false"; rec.Downloaded = false; rec.DueDate = ""; rec.LP = lpid; rec.Objective = obj.id; rec.CMI = ""; App.LocalFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); await App.Database.SaveItemAsync(rec); perc_complete = (rec.CompletionStatus.ToLower() == "completed") ? 100 : (rec.CompletionStatus.ToLower() != "not started") ? 50 : 0; perc_incomplete = (rec.CompletionStatus.ToLower() == "completed") ? 0 : (rec.CompletionStatus.ToLower() != "not started") ? 50 : 100; } else if (String.IsNullOrEmpty(courseRecord.Objective) || String.IsNullOrEmpty(courseRecord.LP)) { courseRecord.Objective = obj.id; courseRecord.LP = lpid; await App.Database.SaveItemAsync(courseRecord); } if (courseRecord != null) { if (courseRecord.ProgressMeasure != null && courseRecord.ProgressMeasure != "") { perc_complete = float.Parse(courseRecord.ProgressMeasure) * 100; perc_incomplete = 100 - perc_complete; } else { perc_complete = (courseRecord.CompletionStatus.ToLower() == "completed") ? 100 : (courseRecord.CompletionStatus.ToLower() == "unknown" || courseRecord.CompletionStatus.ToLower() == "attempted") ? 50 : 0; perc_incomplete = (courseRecord.CompletionStatus.ToLower() == "not started") ? 100 : (courseRecord.CompletionStatus.ToLower() == "completed") ? 100 : 50; } } Doughnut doughnut = new Doughnut(); Grid doughnutGrid = doughnut.CompletionChart("complete", perc_complete, perc_incomplete); //***************************************************** Grid activityContainer = new Grid { Padding = new Thickness(5, 0, 5, 0), ClassId = "course_" + act.id }; activityContainer.RowDefinitions.Add(new RowDefinition { Height = 50 }); activityContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); activityContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); activityContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); Label coursetitle = new Label { Text = act.Name, Style = (Style)Application.Current.Resources["subHeaderStyle"], VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand }; ActivityIndicator spinner = new ActivityIndicator { IsVisible = false, Style = (Style)Application.Current.Resources["spinnerStyle"], HeightRequest = 20 }; Label lbl = new Label() { Text = (courseRecord == null || courseRecord.Downloaded == false) ? "download" : (courseRecord.CompletionStatus.ToLower() == "completed") ? "review" : (courseRecord.CMI == "") ? "open" : "resume", HorizontalOptions = LayoutOptions.Center }; // Create the two buttons that get swapped // DownloadImageButton launchBtn = BuildImageLaunch(act.CourseID, courseRecord, null, lbl); DownloadImageButton downloadBtn = BuildImageDownload(act.CourseID, courseRecord, spinner, lbl); launchBtn.HorizontalOptions = LayoutOptions.Center; downloadBtn.HorizontalOptions = LayoutOptions.Center; launchBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.VerticalOptions = LayoutOptions.EndAndExpand; // Button Grid Grid btnGrid = new Grid() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.EndAndExpand }; btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(20) }); btnGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(80) }); btnGrid.Children.Add(launchBtn, 0, 0); btnGrid.Children.Add(downloadBtn, 0, 0); btnGrid.Children.Add(spinner, 0, 0); btnGrid.Children.Add(lbl, 0, 1); Courses c = new Courses(); downloadBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.Clicked += c.DownloadClicked; launchBtn.Clicked += c.launchCourse; launchBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.LaunchButton = launchBtn; downloadBtn.CourseID = act.CourseID; // add the image CachedImage marquee = BuildMarquee(act.CourseID, false); marquee.HorizontalOptions = LayoutOptions.StartAndExpand; activityContainer.Children.Add(coursetitle, 0, 0); // activityContainer.Children.Add(chartView, 1, 0); activityContainer.Children.Add(doughnutGrid, 1, 0); Grid.SetColumnSpan(coursetitle, 2); activityContainer.Children.Add(marquee, 0, 1); activityContainer.Children.Add(btnGrid, 1, 1); frameContainer.Children.Add(activityContainer); } cardBody.Children.Add(frameContainer); layout.Children.Add(objectiveTitle, 0, 0); layout.Children.Add(AcBtn, 1, 0); layout.Children.Add(cardBody, 0, 1); Grid.SetColumnSpan(cardBody, 2); container.Children.Add(layout); return(true); }