[转]Silverlight 自适应屏幕大小

Silverlight 自适应屏幕大小

时间:2011-03-03 06:03来源:CSDN 作者:欧磊 点击: 1283次

几种方法: 1.这是我在网上搜到的一个代码: 一般来说可以捕捉resize事件,然后做变换: public partial class MainPage:UserControl { public MainPage() this .Loaded+= new RoutedEventHandler(MainPage_Loaded); void MainPage_Loaded( object sender,RoutedEventArgse){ App.Current.Host.Content.Resized+=

  几种方法:

  1.这是我在网上搜到的一个代码:

  一般来说可以捕捉resize事件,然后做变换:

public partial class MainPage : UserControl
{
public MainPage()
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
void MainPage_Loaded(object sender, RoutedEventArgs e) {
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
double width, height;
}
void Content_Resized(object sender, EventArgs e) {
if (!App.Current.Host.Content.IsFullScreen) {
if (width != 0 && height != 0) {
ScaleTransform tt = new ScaleTransform();
App.Current.Host.Content.ActualWidth / width;
App.Current.Host.Content.ActualHeight / height;
this.RenderTransform = tt;
}
else
{
width =App.Current.Host.Content.ActualWidth;
height =App.Current.Host.Content.ActualHeight;
}
}
tt.ScaleY =
tt.ScaleX =
InitializeComponent();
}

  2.去掉的width和hight,使用Grid布局,页面的布局便会随屏幕大小变化而变化。控件的Margin可以全设置为0

  3。采用StackPanel自适应分辨率,而且还有个好处是,里面的图片也可以随着分辨率不同大小也不一样。这点grid没有。

本文来自欧磊的博客,原文地址:http://blog.csdn.net/oulei2008/archive/2011/03/02/6217318.aspx

posted on 2013-09-24 16:57  wiikii  阅读(215)  评论(0编辑  收藏  举报

导航