[UWP]如何在使用操作事件时提高设备性能? [英] [UWP]How to improve the device performance when using the manipulation events?
问题描述
我在画布中有10个矩形,我增加了矩形使用比例值在ManipulationDelta事件中的大小,它在桌面上顺利工作但在设备中无法正常工作。
如何平滑地操作设备中的元素?这是我的代码:
< Canvas Name =" LayoutRoot" &NBSP;宽度=" 300"高度="500">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Red"高度= QUOT; 100"宽度=" 100">
&NBSP; &NBSP; &NBSP; < Rectangle Fill =" Green"高度= QUOT; 100"宽度=" 100">
&NBSP; < / Canvas>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
private void MainPage_OnManipulationDelta(object sender,ManipulationDeltaRoutedEventArgs e)
&NBSP; &NBSP; &NBSP; {
$
foreach(LayoutRoot.Children中的Rectangle rectAngle)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; rectAngle.Width + = e.Cumulative.Scale;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; rectAngle.Height + = e.Cumulative.Scale;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Canvas.SetLeft(rectAngle,LayoutRoot.Width / 2 - rectAngle.ActualWidth / 2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Canvas.SetTop(rectAngle,LayoutRoot.Height / 2 - rectAngle.ActualHeight / 2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
谢谢,
santhiya
你好Santhiya A,
我检查了你的代码,这很简单也没问题。您描述的性能问题,我相信它会在不同的设备中有所不同。我在我的设备中测试了你的代码。它运作良好。
如果您想优化性能,可以参考此文档: 性能
同时查看
优化您的XAML应用程序以获得性能(10 x 10)和
XAML性能:最大化利用XAML构建的通用Windows应用体验的技术
此外,  ; 欢迎
到开发环球Windows应用论坛!
请阅读粘贴帖子,尤其是
发布指南:主题行标签和
Windows 10 SDK和工具的已知问题
请记得下次自己为标题添加标签。
最好的问候,
Xavier Eoro
Hi,
I have 10 rectangles inside the canvas, I have increased the rectangle size in the ManipulationDelta event using the scale values, it is smoothly working in desktop but it not working properly in the device.
How to smoothly manipulate the element in a device? Here my code:
<Canvas Name="LayoutRoot" Width="300" Height="500">
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Green" Height="100" Width="100"/>
</Canvas>
private void MainPage_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
foreach (Rectangle rectAngle in LayoutRoot.Children)
{
rectAngle.Width += e.Cumulative.Scale;
rectAngle.Height += e.Cumulative.Scale;
Canvas.SetLeft(rectAngle, LayoutRoot.Width / 2 - rectAngle.ActualWidth / 2);
Canvas.SetTop(rectAngle, LayoutRoot.Height / 2 - rectAngle.ActualHeight / 2);
}
}
Thanks,
santhiya
Hello Santhiya A,
I have checked your code, it’s really simple and no problem. The performance issue that you described, I believe it will be different in different device. I’ve tested your code in my device. It worked well.
If you want to optimize performance, you could refer this document: Performance
Also check out Optimizing your XAML app for performance (10 by 10) and XAML Performance: Techniques for Maximizing Universal Windows App Experiences Built with XAML
In addition, Welcome to the Developing Universal Windows apps forum!
Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools
Please remember to add tag to title yourself next time.
Best Regards,
Xavier Eoro
这篇关于[UWP]如何在使用操作事件时提高设备性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!