I am trying to get the ActualSize of MyUserControl
before it gets rendered using Measure
methode of UserControl
class as suggested for my previous question. However it is not working. MyUserControl
has an ItemsControl
that is databound with a List
as shown below. The items added through uc.MyCollection = myCollection;
is not getting 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