几种方法:
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没有。