private static void CreateXamlItem(IList <TreeViewNode> children, XamlItem xamlItem) { var label = new Label { VerticalOptions = LayoutOptions.Center, TextColor = Color.Black, Text = xamlItem.Key }; label.SetBinding(Label.TextProperty, "Key"); label.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { xamlItem.Selected = !xamlItem.Selected; }) }); var checkBox = new CheckBox() { Margin = new Thickness(10, 5, 10, 0), HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, }; checkBox.SetBinding(CheckBox.IsCheckedProperty, "Selected", mode: BindingMode.TwoWay); var xamlItemTreeViewNode = CreateTreeViewNode(xamlItem, label, checkBox, true); children.Add(xamlItemTreeViewNode); }
public XamlItemGroup GroupData(IList <AccountingModel> accountingOptions) { var accountings = accountingOptions.OrderBy(x => x.ParentId); var accountingGroup = new XamlItemGroup(); foreach (var dept in accountings) { var itemGroup = new XamlItemGroup { Name = dept.Name, GroupId = dept.Number }; if (dept.ParentId <= 0) { accountingGroup.Children.Add(itemGroup); } else { XamlItemGroup parentGroup = null; foreach (var group in accountingGroup.Children) { parentGroup = FindParent(group, dept); if (parentGroup != null) { if (parentGroup.Children.Count == 0) { var item = new XamlItem { ItemId = dept.Number, ParentId = dept.ParentId, Key = dept.Name, SelectedCommand = ReactiveCommand.Create <XamlItem>(r => { if (r == null) { return; } //r.Selected = r.Selected; return; }) }; parentGroup.XamlItems.Add(item); } else { parentGroup.Children.Add(itemGroup); break; } } } } } return(accountingGroup); }
public static XamlItemGroup GroupData() { var company = GetCompany(); var departments = GetDepartments().OrderBy(x => x.ParentDepartmentId); var employees = GetEmployees(); var companyGroup = new XamlItemGroup(); companyGroup.Name = company.CompanyName; foreach (var dept in departments) { var itemGroup = new XamlItemGroup(); itemGroup.Name = dept.DepartmentName; itemGroup.GroupId = dept.DepartmentId; // Employees first var employeesDepartment = employees.Where(x => x.DepartmentId == dept.DepartmentId); foreach (var emp in employeesDepartment) { var item = new XamlItem(); item.ItemId = emp.EmployeeId; item.Key = emp.EmployeeName; itemGroup.XamlItems.Add(item); } // Departments now if (dept.ParentDepartmentId == -1) { companyGroup.Children.Add(itemGroup); } else { XamlItemGroup parentGroup = null; foreach (var group in companyGroup.Children) { parentGroup = FindParentDepartment(group, dept); if (parentGroup != null) { parentGroup.Children.Add(itemGroup); break; } } } } return(companyGroup); }
public static void CreateXamlItem(IList <TreeViewNode> children, XamlItem xamlItem) { var label = new Label { VerticalOptions = LayoutOptions.Center, TextColor = Color.Black }; label.SetBinding(Label.TextProperty, "Key"); var xamlItemTreeViewNode = CreateTreeViewNode(xamlItem, label, true); children.Add(xamlItemTreeViewNode); }