private void ToggleClicked(object sender, EventArgs e) { #if DEBUG var sw = new Stopwatch(); sw.Start(); Trace.Write("MasterDetail Toggling..."); #endif if (MasterDetail.GetToggleDetailOnClicked(sender as View) || ToggleOnMasterClick) { if (!string.IsNullOrEmpty(SelectionGroup) && !IsDetailVisible) { if (selectionGroups.ContainsKey(SelectionGroup)) { var list = selectionGroups[SelectionGroup]; foreach (var c in list) { c.IsDetailVisible = false; } } } IsDetailVisible = !IsDetailVisible; } #if DEBUG sw.Stop(); Trace.WriteLine("MasterDetail Toggled: " + sw.ElapsedMilliseconds); #endif }
private static void CreateDetailControls(MasterDetail control) { if (control.detailView == null) { Layout cached = null; control.detailViewCached?.TryGetTarget(out cached); if (cached != null) { control.detailView = cached; } else { control.detailView = control.ViewFromTemplate(control.DetailTemplate, control.DetailBindingContext ?? control.BindingContext); if (control.detailViewCached == null) { control.detailViewCached = new WeakReference <Layout>(control.detailView); } else { control.detailViewCached.SetTarget(control.detailView); } } } }
private static void AddDetailControls(MasterDetail control, bool isVisible = false) { if (!control.detailAdded) { control.detailView.IsVisible = isVisible; control.Children.Add(control.detailView); control.detailAdded = true; } }
private static void SetOnMasterClick(MasterDetail control) { if (!control.toggleClickAssigned && !control.ToggleOnMasterClick) { control.toggleClickAssigned = true; //allow 2 level indentation Func <Element, bool> assignClick = (Element c) => { if (MasterDetail.GetToggleDetailOnClicked(c)) { if (c is Button) { (c as Button).Clicked += control.ToggleClicked; } else if (c is ExtendedLabel) { (c as ExtendedLabel).Clicked += control.ToggleClicked; } return(true); } return(false); }; foreach (var c in control.masterView.Children) { if (c is Layout <View> ) { foreach (var c2 in (c as Layout <View>).Children) { if (assignClick(c2)) { break; } } } else if (assignClick(c)) { break; } } } }
private void ToggleClicked(object sender, EventArgs e) { if (MasterDetail.GetToggleDetailOnClicked(sender as View)) { if (!string.IsNullOrEmpty(SelectionGroup) && !IsDetailVisible) { if (selectionGroups.ContainsKey(SelectionGroup)) { var list = selectionGroups[SelectionGroup]; foreach (var c in list) { c.IsDetailVisible = false; } } } IsDetailVisible = !IsDetailVisible; } }
private static void MasterIsVisibleChanged(BindableObject bindable, object oldValue, object newValue) { var control = bindable as MasterDetail; if (control.MasterTemplate == null) { return; } if ((bool)newValue) { if (control.masterView == null) { control.masterView = control.ViewFromTemplate(control.MasterTemplate, control.BindingContext); if (control.detailAdded) { control.Children.Clear(); } control.Children.Add(control.masterView); if (control.detailAdded) // JIC, order of calls to master and detail visible change can be any { if (control.detailView != null) { control.Children.Add(control.detailView); } else { control.detailAdded = false; } } control.masterAdded = true; } else if (!control.masterAdded) { if (!control.detailAdded) { control.Children.Add(control.masterView); } else { control.Children.Clear(); control.Children.Add(control.masterView); if (control.detailView != null) { control.Children.Add(control.detailView); } } control.masterAdded = true; } else { control.masterView.IsVisible = true; } if (!control.toggleClickAssigned) { control.toggleClickAssigned = true; //allow 2 level indentation Func <Element, bool> assignClick = (Element c) => { if (MasterDetail.GetToggleDetailOnClicked(c)) { if (c is Button) { (c as Button).Clicked += control.ToggleClicked; } else if (c is ExtendedLabel) { (c as ExtendedLabel).Clicked += control.ToggleClicked; } return(true); } return(false); }; foreach (var c in control.masterView.Children) { if (c is Layout <View> ) { foreach (var c2 in (c as Layout <View>).Children) { if (assignClick(c2)) { break; } } } else if (assignClick(c)) { break; } } } } else // hide Master { if (control.MasterDestroyInvisible && control.masterAdded) { control.Children.Remove(control.masterView); control.masterAdded = false; } else if (control.masterView != null) { control.masterView.IsVisible = false; } } }