silverlight
发布时间:2022-05-04 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使silverlight适应IE窗口大小的方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
Pete Brown在它的BLOG中提到了一个按自定义比例使用silverlight适应IE窗口大小的方法 原文如下:How to Resize a Silverlight 2 App and Keep the Same Aspect Ratio
其核心代码如下( Xaml ): < UserControl x:Class ="PeteBr
Pete Brown在它的BLOG中提到了一个按自定义比例使用silverlight适应IE窗口大小的方法
原文如下:How to Resize a Silverlight 2 App and Keep the Same Aspect Ratio
其核心代码如下(
Xaml
):
<
UserControl
x:Class
="PeteBrown.SilverlightScalingExample.Page"
xmlns
="http://scheR_934_11845@as.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://scheR_934_11845@as.microsoft.com/winfx/2006/xaml"
>
Grid
x:Name
="LayoutRoot"
BACkground
="Cornsilk"
ShowGridLines
="True"
Width
="400"
Height
="300"
renderTransformOrigin
="0.5 0.5"
Grid.RenderTransform
ScaleTransform
="PageScale"
ScaleX
="1"
ScaleY
="1"
/>
</
…
Grid
UserControl
>
public
partial
class
Page : UserControl
{
//
this is the aspect ratio we want to maintain
you can specify this all sorts of ways, but the
easiest is to take the original size and divide
X by Y (4:3 or 1.333 in this casE)
private
const
double
_originalWidth
=
400
;
_originalHeight
300
_originalAspectRatio
_originalWidth
/
_originalHeight;
Page()
{
InitializeComponent();
wire up the Event handler. This is a great addition
to silverlight, as you used to have to hook into the
browser event yourself
SizeChanged
+=
new
SizeChangedEventHandler(Page_SizeChanged);
}
void
Page_SizeChanged(
object
sender, SizeChangedEventArgs E)
{
if
(e.NewSize.Width
<
||
e.NewSize.Height
_originalHeight)
{
don't shrink
PageScale.ScaleX
1.0
;
PageScale.ScaleY
;
}
else
{
resize keeping aspect ratio the same
e.NewSize.Height
>
_originalAspectRatio)
{
height is our consTraining property
PageScale.ScaleY
_originalHeight;
PageScale.ScaleX
PageScale.ScaleY;
}
{
either width is our consTraining property, or the user
managed to nail our aspect ratio perfectly.
PageScale.ScaleX
e.NewSize.Width
_originalWidth;
PageScale.ScaleY
PageScale.ScaleX;
}
}
}
}
这是一个很有用的小技巧,所以在这里做一个记号,看看将来是否能用得上:)
大佬总结
以上是大佬教程为你收集整理的使silverlight适应IE窗口大小的方法全部内容,希望文章能够帮你解决使silverlight适应IE窗口大小的方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。