当前位置:网站首页>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();
}边栏推荐
- 如果是测试 axi dma抓数的话 看这里
- 拥抱Cmake小朋友 简单又实用,但是不灵活
- JS new一个构造器发生了什么?从零手写一个new方法
- 使用 Allatori 进行 Jar 包混淆
- A complete cross-compilation environment records the shell scripts generated by peta
- 如何找到某个 ABAP structure 某字段的源头来自哪个数据库表
- 关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
- 面试官:索引为什么会失效?
- Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO
- 搭建MyCat2双主双从的MySQL读写分离
猜你喜欢

vscode离线安装插件方法

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

v-model的使用

ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators

使用.NET简单实现一个Redis的高性能克隆版(二)

如何进行AI业务诊断,快速识别降本提效增长点?

基于HDF的LED驱动程序开发(2)

linkboy 5.0 正式发布,新增语音识别、图像识别

Desthiobiotin-PEG4-Azide_脱硫生物素-叠氮化物 100mg

图片延迟加载、预加载
随机推荐
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO
多商户商城系统功能拆解22讲-平台端分销商品
Quantitative trading robot system development
Apache服务器配置多个站点
getBoundingClientRect
刷题-洛谷-P1200 你的飞碟在这儿Your Ride Is Here
Use "green computing" technology to promote sustainable development of computing power
Apache服务器的配置[通俗易懂]
简易数据缓存层的建立
v-model的使用
Red5搭建直播平台
刷题-洛谷-P1304 哥德巴赫猜想
基于HDF的LED驱动程序开发(2)
如何推动乡村振兴的落地
Seata source code analysis: various message processing processes of seata server
Latex分章节、分段落编译:input{}与include{}的区别
格密码入门