后台代码,控件按比例缩放:
if (currentWidth > RECOMMAND_SCREEN_WIDTH || currentHeight > RECOMMAND_SCREEN_HEIGHT)
{
CompositeTransform ctf = new CompositeTransform();
ctf.ScaleX = currentWidth / RECOMMAND_SCREEN_WIDTH;
ctf.ScaleY = currentHeight / RECOMMAND_SCREEN_HEIGHT;
//沿着中心点进行缩放,这样的话,在多次缩放后,不会偏移原来位置
ctf.CenterX = currentWidth / 2;
ctf.CenterY = currentHeight / 2;
ControlMainPage.RenderTransform = ctf;
}
XAML代码:
<UserControl x:Class="SLCenterLayout.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" x:Name="ControlMainPage"
>
<UserControl.Resources>
</UserControl.Resources>
<UserControl.RenderTransform>
<CompositeTransform />
</UserControl.RenderTransform>
<ScrollViewer x:Name="LayoutRoot" MaxWidth="1300" MaxHeight="685"VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="Black">
<Grid HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image Source="2.jpg"/>
<TextBlock Grid.Row="1" FontSize="30" Foreground="White">WP8</TextBlock>
</Grid>
</ScrollViewer>
</UserControl>
Silverlight控件"UserControls",根据比例进行缩放,兼容分辨率方法疑问???
问题一:不是只要不为"UserControls"设置固定的高度和宽度,它就可以铺满整个屏幕的吗??? 为什么还要设置按照比例缩放???
问题二:为“UserControl”设置这样的缩放比例有什么好处??? 它其中的控件也会随着比例进行缩放吗??? 就像 “Image”和“TextBlock”。。。
问题三:“Grid”不用设置各列的百分比吗???
Science and technology is my lover.