首页 技术 正文
技术 2022年11月9日
0 收藏 713 点赞 3,939 浏览 2036 个字

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="" d:DesignWidth="" x:Name="ControlMainPage" >
<UserControl.Resources> </UserControl.Resources>
<UserControl.RenderTransform>
<CompositeTransform />
</UserControl.RenderTransform> <ScrollViewer x:Name="LayoutRoot" MaxWidth="" MaxHeight=""VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="Black">
<Grid HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image Source="2.jpg"/>
<TextBlock Grid.Row="" FontSize="" Foreground="White">小米手机快发货啊</TextBlock>
</Grid>
</ScrollViewer>
</UserControl>

xaml.cs:

using System;
using System.Windows.Controls;
using System.Windows.Media;namespace SLCenterLayout
{
public partial class MainPage : UserControl
{
//标准显示宽度
private const double RECOMMAND_SCREEN_WIDTH = ; //标准显示高度
private const double RECOMMAND_SCREEN_HEIGHT = ; public MainPage()
{
InitializeComponent();
App.Current.Host.Content.Resized+=new EventHandler(Content_Resized);
} private void ChangePageRenderSize(double currentWidth, double currentHeight)
{
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 / ;
ctf.CenterY = currentHeight / ;
ControlMainPage.RenderTransform = ctf;
}
} private void Content_Resized(object sender, EventArgs e)
{
ChangePageRenderSize(ControlMainPage.ActualWidth, ControlMainPage.ActualHeight);
} }

说明:Resized事件:因为我们在对页面缩放的时候,很重要的一对数据就是当前页面的宽度和高度,而这对数据,我们可以在Resized事件里面获得
MSDN关于Resized事件的阐述是:

  此事件将在开始加载 Silverlight 插件过程中发生。在发生该事件后,ActualHeight 或 ActualWidth 的值是可靠的。在这一时刻之前,ActualHeight 或 ActualWidth 的值不可靠。

http://blog.csdn.net/hemingliang1987/article/details/8646669

上一篇: Java内存溢出详解
下一篇: elr_memory_pool详解
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295