当前位置:网站首页>Win10 uwp use ScaleTransform magnify an element
Win10 uwp use ScaleTransform magnify an element
2022-08-04 20:05:00 【Lin Dexi】
本文告诉大家如何通过 ScaleTransform 放大元素 Zoom in an element method has many a,通过 ScaleTransform Amplification is halal
在 UWP 中 ScaleTransform 是属于 RenderTransform 的内容,所有的 UIElement 都有 RenderTransform 属性,By setting this attribute can be done at run time to modify the rendering elements
As a new simple UWP 程序,Put a button inside
<Button VerticalAlignment="Center" HorizontalAlignment="Center" Content="Click" Click="Button_OnClick">
</Button>If you want to amplify the button shows two times,简单的方法是使用 ScaleTransform Set two directions amplification
修改一下代码
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Margin="10,10,10,10" Content="Enlarge button before">
</Button>
<Button VerticalAlignment="Center" HorizontalAlignment="Center" Content="放大的按钮">
<Button.RenderTransform>
<ScaleTransform x:Name="ScaleTransform" ScaleX="2" ScaleY="2"></ScaleTransform>
</Button.RenderTransform>
</Button>
</StackPanel>代码请看 github
从上面看到 ScaleTransform Support the two directions of larger,Can set two directions to different values
其实 ScaleTransform Can also set the zoom center,From that point as the center amplification
The default is not set from (0,0) The point is the upper left corner of the PM amplification,After amplification will keep unchanged the coordinates of the upper left corner
Most of the time will be used to enlarge from center,Enlarge the center of the need to set the zoom element from the center,请看代码,When click on the button to zoom in,Center is the center button
<Button VerticalAlignment="Center" HorizontalAlignment="Center" Content="放大的按钮" Click="Button_OnClick">
<Button.RenderTransform>
<ScaleTransform x:Name="ScaleTransform" ScaleX="1" ScaleY="1"></ScaleTransform>
</Button.RenderTransform>
</Button> private void Button_OnClick(object sender, RoutedEventArgs e)
{
var button = (Button) sender;
ScaleTransform.CenterX = button.ActualWidth / 2;
ScaleTransform.CenterY = button.ActualHeight / 2;
ScaleTransform.ScaleX = 1.5;
ScaleTransform.ScaleY = 1.5;
}Don't set to contrast the enlarge from the top left corner
private void Button_OnClick(object sender, RoutedEventArgs e)
{
ScaleTransform.ScaleX = 1.5;
ScaleTransform.ScaleY = 1.5;
}Then how to do scaling,
I use a little advantage under the method to do animation,Friend, please don't learn the writing
private void Button_OnClick(object sender, RoutedEventArgs e)
{
Task.Run(async () =>
{
while (true)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
ScaleTransform.ScaleX++;
ScaleTransform.ScaleY++;
});
await Task.Delay(100);
}
});
}I open a thread,Use an infinite loop,在里面使用 Task.Delay 做延迟
因为在 UWP Is not the main thread is unable to access the main thread element,所以就需要通过 Dispatcher.RunAsync Make the code in the main thread running
So a little halal method is how to do it?通过 xaml Write animation is a good method
<Button VerticalAlignment="Center" HorizontalAlignment="Center" Content="放大的按钮" Click="Button_OnClick">
<Button.Resources>
<Storyboard x:Key="Storyboard">
<DoubleAnimation Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleX" To="1.5" Duration="0:0:1"></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleY" To="1.5" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</Button.Resources>
<Button.RenderTransform>
<ScaleTransform x:Name="ScaleTransform" ScaleX="1" ScaleY="1"></ScaleTransform>
</Button.RenderTransform>
</Button>At this time by clicking on the button to get the resources,运行动画
private void Button_OnClick(object sender, RoutedEventArgs e)
{
var button = (Button) sender;
var storyboard = (Storyboard) button.Resources["Storyboard"];
storyboard.Begin();
}边栏推荐
- Client Side Cache 和 Server Side Cache 的区别
- How to use the Chrome DevTools performance tab
- MySQL字段类型
- ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
- C#弹出询问对话框
- idea源码无法下载
- win10 uwp modify picture quality compress picture
- KubeSphere简介,功能介绍,优势,架构说明及应用场景
- The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
- In July 2022, domestic database memorabilia
猜你喜欢

简单理解 JS 事件循环

Go study notes (Part 1) Configuring the Go development environment

Chrome安装zotero connector 插件

二叉树是否对称

用“绿色计算“技术推动算力可持续发展

Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO

对比几类主流的跨端技术方案

蚂蚁集团时序数据库CeresDB正式开源

多用户同时远程登录连接到一台服务器

"WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!
随机推荐
PriorityQueue类的使用及底层原理
Use "green computing" technology to promote sustainable development of computing power
JS new一个构造器发生了什么?从零手写一个new方法
使用.NET简单实现一个Redis的高性能克隆版(二)
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
JS手写JSON.stringify() (面试)
ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
性能测试流程
面试官:索引为什么会失效?
c sqlite...
Go学习笔记(篇一)配置Go开发环境
常用正则表达式[通俗易懂]
腾讯云胡启明:Kubernetes云上资源的分析与优化
Force KouTi (5), the longest text string back
Tensorflow2 环境搭建
Tear down the underlying mechanism of the five JOINs of SparkSQL
多用户同时远程登录连接到一台服务器
idea源码无法下载
华为WLAN技术:AP上线及相关模板的配置实验
数据安全解决方案的发展