Windows phone 7 用户控制绘图Silverlight 4
我创建一个usercontrol只是为了包含一个图像,因为我必须使用Measureoverride和arrangeoverride方法,并且我不能创建子类(图像被选中)。。。无论如何,问题是当我调用这个.Image.Measure(SizeIwantToGiveTotheImage)时,图像的desiredSize字段没有设置。。。有人知道为什么吗? 我以前一直在管理布局方法,它很有效。。。 这是代码(我已经检查了所有其他尺寸,没有一个是0或NaN)Windows phone 7 用户控制绘图Silverlight 4,windows-phone-7,silverlight-4.0,Windows Phone 7,Silverlight 4.0,我创建一个usercontrol只是为了包含一个图像,因为我必须使用Measureoverride和arrangeoverride方法,并且我不能创建子类(图像被选中)。。。无论如何,问题是当我调用这个.Image.Measure(SizeIwantToGiveTotheImage)时,图像的desiredSize字段没有设置。。。有人知道为什么吗? 我以前一直在管理布局方法,它很有效。。。 这是代码(我已经检查了所有其他尺寸,没有一个是0或NaN) 最后,这是一个非常简单的解决方案。。。在Us
最后,这是一个非常简单的解决方案。。。在UserControl的构造函数中,我添加了这一行:this.Content=image; 现在用户控件的内容在屏幕中绘制:-)
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;
}