private bool RemoveVisualElement(DesignSurfacePair <VisualElement> pair) { // we don't allow the root element to be removed. if (pair.XenWidget.Parent == null) { return(false); } var parentId = pair.XenWidget.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); } // 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 RemoveXenWidget(DesignSurfacePair <VisualElement> pair) { var child = pair.XenWidget; var parent = child.Parent; if (parent == null) { return(false); } if (!parent.Children.Contains(child)) { return(false); } parent.Children.Remove(child); return(true); }
public override DesignSurfacePair <VisualElement> this[string id] { get { // No hierarchy exists, so we return null. if (Root == null) { return(null); } if (string.IsNullOrWhiteSpace(id)) { return(null); } VisualElement 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 DesignSurfacePair <VisualElement> { XenWidget = match, VisualElement = ve }; return(result); } }
private void SetAttachedProperty(object value, AttachedPropertyInfo attachedProperty, DesignSurfacePair <VisualElement> pair) { var set = value; if (set != null && (value.Equals("NULL") || value.Equals("null"))) { set = null; } if (set != null) { set = Convert.ChangeType(value, attachedProperty?.GetMethod.ReturnType); } try { attachedProperty?.SetMethod.Invoke(null, new[] { pair.VisualElement, set }); } catch (ArgumentException) { // ignored for now; this should be logged and the user should be notified with a validation message } catch (Exception) { // ignored for now; this should be logged and the user should be notified with a validation message } }
/// <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(VisualElement child, DesignSurfacePair <VisualElement> parent) { return(SetParent(child, parent.VisualElement)); }