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没有。
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没有。
相关文章推荐
- Silverlight 自适应屏幕大小
- android 简单的弹出框(在屏幕中间,传string[],根据内容框框大小自适应)
- silverlight 自适应窗口大小的设置
- Android自适应屏幕方向、大小和分辨率,及字体设置
- Android开发屏幕大小自适应
- Android应用程序自适应屏幕大小的解决办法
- Android开发之屏幕大小自适应
- Android开发之屏幕大小自适应
- android 应用程序自适应屏幕大小
- Android手机字体自适应屏幕大小
- html移动端自适应屏幕大小
- Android系统自适应屏幕大小
- android自适应屏幕方向和大小
- 如何设计自适应屏幕大小的网页
- Div 自适应屏幕大小
- Android: android自适应屏幕方向和大小
- html图片自适应屏幕大小(手机)
- css 图片自适应屏幕大小
- Android自适应不同分辨率或不同屏幕大小 (转)
- android自适应屏幕方向和大小