Я создал usercontrol просто для того, чтобы содержать Image, потому что я должен использовать методы Measureoverride иrangeoverride, и я не могу создать подкласс (Image is seled) ... в любом случае, дело в том, что когда я вызываю this.Image.Measure (SizeIwantto to the image) поле требуемого размера изображения не установлено ... кто-нибудь знает почему?Я управлял методами Layouting раньше, и это сработало ... Вот код (я уже проверил все другие размеры, и ни один из них не равен 0 или NaN)
protected override Size MeasureOverride(Size availableSize)
{
//the size that the element wants to have
Size imageDesiredSize = new Size();
imageDesiredSize = availableSize;
//if the current element's size is a pertentage
if ((futureHeight != 0))
{
imageDesiredSize.Height = availableSize.Height * futureHeight / 100;
}
if ((futureWidth != 0))
{
imageDesiredSize.Width = availableSize.Width * futureWidth / 100;
}
if (widthWrap)
{
imageDesiredSize.Width = ((BitmapImage)this.Source).PixelWidth;
}
if (heightWrap)
{
imageDesiredSize.Height = ((BitmapImage)this.Source).PixelHeight;
}
System.Diagnostics.Debug.WriteLine("imagedesired" + imageDesiredSize);
this.image.Measure(imageDesiredSize);
System.Diagnostics.Debug.WriteLine("desiredsize" + this.image.DesiredSize);
return imageDesiredSize;
}