public bool RemoveVisualElement(SurfacePair pair) { // we don't allow the root element to be removed. if (pair.UIWidget.Parent == null) { return(false); } var parentId = pair.UIWidget.Parent.Id; var parentPair = this[parentId]; if (parentPair == null) { return(false); } // this is the only child of the content page if (parentId == Root.Id) { var page = parentPair.VisualElement as ContentPage; if (page != null) { page.Content = null; return(true); } } // this maybe a layout control var viewContainer = parentPair.VisualElement as IViewContainer <View>; var childView = pair.VisualElement as View; var parentView = parentPair.VisualElement; // we can only remove view types; this shouldn't happen. if (childView == null) { return(false); } // is this a content property? if (viewContainer == null && ElementHelper.HasContentProperty(parentView)) { ElementHelper.ClearContentProperty(parentView); return(true); } // is it a layout control? i.e. stacklayout, grid.. if (viewContainer == null) { return(false); } // made it this far, it's a layout control. viewContainer.Children.Remove(childView); return(true); }
private bool RemoveUIWidget(SurfacePair pair) { var child = pair.UIWidget; var parent = child.Parent; if (parent == null) { return(false); } if (!parent.Children.Contains(child)) { return(false); } parent.Children.Remove(child); return(true); }
public override SurfacePair this[string id] { get { // No hierarchy exists, so we return null. if (Root == null) { return(null); } if (string.IsNullOrWhiteSpace(id)) { return(null); } Element ve; if (_lookup.ContainsKey(id)) { ve = _lookup[id]; } else { return(null); } // Placing the recursive lookup here to save cycles if the view is not "cached" var all = Root.GetNodeAndDescendants(); var match = all.FirstOrDefault(w => w.Id != null && w.Id.Equals(id)); var result = new SurfacePair { UIWidget = match, VisualElement = ve }; return(result); } }
/// <summary> /// Attach the child view to the parent. /// Once attached, the visual tree will be rebuilt. /// </summary> /// <param name="child"></param> /// <param name="parent"></param> /// <returns> /// Returns true if attached; otherwise, false. /// </returns> public override bool SetParent(Element child, SurfacePair parent) { return(SetParent(child, parent.VisualElement)); }