I\'m using a binding of the form
{Binding RelativeSource={RelativeSource Self}, Path=Children.Count, Converter={StaticResource CountToDimensionConverter}, C
public class GridEx : Grid, INotifyPropertyChanged
{
public delegate void ChildrenUpdatedEventHandler(DependencyObject visualAdded, DependencyObject visualRemoved);
public event ChildrenUpdatedEventHandler ChildrenUpdated;
public event PropertyChangedEventHandler PropertyChanged;
public bool HasChildren => Children.Cast().Where(element => element != null).Count() > 0;
public int ChildCount => Children.Cast().Where(element => element != null).Count();
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
{
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
ChildrenUpdated?.Invoke(visualAdded, visualRemoved);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HasChildren)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ChildCount)));
}
}
Use property ChildCount
instead.