• Silverlight自动根据屏幕分辨率进行布局


    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">小米手机快发货啊</TextBlock>
             </Grid>
         </ScrollViewer>
     </UserControl>
    View Code

    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 = 1300;
    
             //标准显示高度
            private const double RECOMMAND_SCREEN_HEIGHT = 685;
    
             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 / 2;
                     ctf.CenterY = currentHeight / 2;
                     ControlMainPage.RenderTransform = ctf;
                 }
             }
    
             private void Content_Resized(object sender, EventArgs e)
             {
                 ChangePageRenderSize(ControlMainPage.ActualWidth, ControlMainPage.ActualHeight);
             }
    
         }
    View Code

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

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

     

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

  • 相关阅读:
    Docker学习笔记07_网络配置
    Docker学习笔记06_部署appache+tomcat+redis+mongo+python
    Docker学习笔记05_部署nginx+php+mysql+phpmyadmin
    Docker学习笔记04_镜像管理
    Docker学习笔记03_容器的简单应用
    Docker学习笔记02_基本操作
    Docker学习笔记01_CentOS 7安装Docker
    Cisco Ironport ESA配置拒收黑名单
    CentOS 7安装Cobra
    jvm内存模型、常见参数及调优
  • 原文地址:https://www.cnblogs.com/zxbzl/p/3499496.html
Copyright © 2020-2023  润新知