I am trying to get ActualSize MyUserControl before getting the render using the Measure method of UserControl , as suggested for my previous question . However, it does not work. MyUserControl has an ItemsControl , which is a data binding with a List , as shown below. Elements added via uc.MyCollection = myCollection; are not reflected in uc.DesiredSize.Height .
MyUserControl uc= new MyUserControl(); uc.AName = "a1"; uc.Width = 194; uc.MyCollection = myCollection; //myCollection is a List databound to ItemsControl inside MyUserControl uc.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); uc.Arrange(new Rect(0, 0, uc.DesiredSize.Width, uc.DesiredSize.Width)); //Needed? uc.UCHeight = uc.DesiredSize.Height; //size of items databound to ItemsControl not reflected here uc.UCWidth = uc.DesiredSize.Width; uc.Margin = new Thickness(34, 42, 0, 0); myRoot.Children.Add(uc); //myRoot is Canvas
source share