您的位置:首页 > 其它

Silverlight 自适应屏幕大小

2011-03-02 10:26 417 查看
几种方法:

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.去掉<usercontrol ></usecontrol>的width和hight,使用Grid布局,页面的布局便会随屏幕大小变化而变化。控件的Margin可以全设置为0

3。采用StackPanel自适应分辨率,而且还有个好处是,里面的图片也可以随着分辨率不同大小也不一样。这点grid没有。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: