使silverlight适应IE窗口大小的方法

使silverlight适应IE窗口大小的方法,第1张

概述    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://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.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窗口大小的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1055040.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存