当前位置:网站首页>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();
}边栏推荐
- June To -.-- -..- -
- 【着色器实现Glitch单项故障闪烁效果(与Television效果不同)_Shader效果第十四篇】
- The difference between Client Side Cache and Server Side Cache
- C#弹出询问对话框
- 成品升级程序
- Client Side Cache 和 Server Side Cache 的区别
- How to manually download and install SAP Fiori tools - Extension Pack for Visual Studio Code
- run command for node
- Nuxt.js的优缺点和注意事项
- KubeSphere简介,功能介绍,优势,架构说明及应用场景
猜你喜欢

【Web漏洞探索】跨站脚本漏洞

面试官:JVM运行时数据区包含哪几部分?作用是啥?

阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64

刷题-洛谷-P1179 数字统计

零知识证明笔记——私密交易,pederson,区间证明,所有权证明

CAS :80750-24-9(脱硫生物素 NHS 酯)

C#弹出询问对话框

面试官:索引为什么会失效?

Use "green computing" technology to promote sustainable development of computing power

小软件大作用 | 如何省时省力进行Gerber图层快速对比?
随机推荐
win10终端中如何切换磁盘
v-model的使用
nr部分计算
Use "green computing" technology to promote sustainable development of computing power
The difference between Client Side Cache and Server Side Cache
【有奖征文】秋招特训,打造你的专属产品体验
多商户商城系统功能拆解22讲-平台端分销商品
使用 Allatori 进行 Jar 包混淆
LED的C语言应用程序
华为WLAN技术:AP上线及相关模板的配置实验
getBoundingClientRect
Aura clock chip generation configuration file script
jMeter Thread group 对应的 constant timer
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
SAP UI5 ensures that the control id is globally unique implementation method
Force KouTi (5), the longest text string back
JS new一个构造器发生了什么?从零手写一个new方法
vs Code 运行一个本地WEB服务器
成品升级程序
SAP UI5 确保控件 id 全局唯一的实现方法