private static void OnItemsSourceChanged(AutoGrid grid, object?oldValue, object?newValue) { var sequence = newValue as IEnumerable <object> ?? newValue.To().Enumerable(); grid.Children.Clear(); sequence.BindTo(grid.Children.WrapAsTypedList(), (o, e) => o == e || o == (e as ContentPresenter)?.Content, x => { var element = x as UIElement ?? CreateContentPresenter(x, grid); if (element != null) { element.Visibility = Visibility.Collapsed; } return(element); }, e => e != null, null, grid.InvalidateChildren); }
private static UIElement?CreateContentPresenter(object?data, AutoGrid container) { var element = (FrameworkElement)Selector.SelectTemplate(data, container)?.LoadContent();// new ResourceContentPresenter{Content = data}; if (element is ContentPresenter x) { x.Content = data; } else if (element is ContentControl y) { y.Content = data; } else if (element != null) { element.DataContext = data; } return(element); }
private static void OnDefaultSizeChanged(AutoGrid grid, string oldValue, string newValue) { grid.DefaultGridLength = newValue == null ? default(GridLength?) : grid.CreateGridLength(newValue); //grid.InvalidateChildren(); }
private static void OnColumnOrRowSizesChanged(AutoGrid grid, string oldValue, string newValue) { //grid.InvalidateChildren(); }