积极答复者
请问怎么样可以实现自动调整屏幕大小?

问题
-
发布后的产品的画面如何才能做到自动调整屏幕大小,因为做的东西经常有打开后显示不完全的问题.
我看了一下,咱们论坛这个拍卖专题也是这样,我的屏幕在正常大小下无法显示完全,只能缩小字体到75%才可以全部显示http://silverlightchina.com/sale/
答案
-
你好,
一般来说可以捕捉resize事件,然后做变换:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
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();
tt.ScaleX =
App.Current.Host.Content.ActualWidth / width;
tt.ScaleY =
App.Current.Host.Content.ActualHeight / height;
this.RenderTransform = tt;
}
else
{
width =
App.Current.Host.Content.ActualWidth;
height =
App.Current.Host.Content.ActualHeight;
}
}
}
}
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Allen Chen - MSFTModerator 2009年8月3日 7:15
全部回复
-
你好,
一般来说可以捕捉resize事件,然后做变换:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
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();
tt.ScaleX =
App.Current.Host.Content.ActualWidth / width;
tt.ScaleY =
App.Current.Host.Content.ActualHeight / height;
this.RenderTransform = tt;
}
else
{
width =
App.Current.Host.Content.ActualWidth;
height =
App.Current.Host.Content.ActualHeight;
}
}
}
}
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Allen Chen - MSFTModerator 2009年8月3日 7:15