本文介绍了[UWP] [C#] [Visual Tree] [渲染管道]如何在渲染过程中使用根Visual Tree或Visual Tree元素注册回调事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在动态地向Visual Tree添加对象。可视树支持呈现XAML对象和Visual对象。

I am dynamically adding objects to a Visual Tree. The visual tree support rendering both XAML objects and Visual objects.

大部分(如果不是全部)我的XAML和Visual对象都插入到ContainerVisual中。我希望能够设置/调整XAML或Visual元素位置(通过调用CreateContainerVisual创建的视觉效果),例如在渲染过程中。

Most of, if not all of, my XAML and Visual objects are inserted into a ContainerVisual. I want the ability to set/adjust a XAML or Visual elements position (a visual created from a call to CreateContainerVisual) for example during rendering.

示例用例:

这适用于UWP桌面,移动电话,手机等应用。并非所有功能都可用于每个风味设备。

This is for a UWP desktop, mobile, phone etc. app. Not all features will be available on every flavored device.

对于此特定用例,该应用程序的Scrollview为1080 x 1080.Scrollview包含一个2160 x 2160的Canvas。  

For this particular use case, the app has a Scrollview that is 1080 x 1080. The Scrollview contains a Canvas that is 2160 x 2160. 

大多数XAML和Visual元素在用户滑动滚动条缩略图时水平和垂直滚动。

Most XAML and Visual elements scroll both horizontally and vertically as a user slides the scroll bars thumbnail.

1。一些视觉效果需要保持其水平位置,但垂直滚动。   

1. Some visuals need to hold their horizontal position, but scroll vertically.   

2。一些视觉效果需要保持垂直位置,但需要水平滚动。

2. Some visuals need to hold their vertical position, but scroll horizontally.

我一直在寻找一种方法来设置一个'回调'事件,以便在渲染Canvas时调用它。在滚动操作期间的某个时刻,将设置Canvas在ScrollView中的位置并渲染对象。我希望(或者可能想要)在刷新屏幕之前在Canvas中调整XAML
或Visual对象位置。

I have been looking for a way to set a 'callback' event to be called as a Canvas is being rendered. At some point during a scroll operations, the Canvas's position in the ScrollView is set and objects are rendered. I want (or may want) to adjust an XAML or Visual objects position within the Canvas before the screen is refreshed.

XAML有一些"相似"的功能使用:ManipulationStarted,  ManipulationDelta,  ManipulationCompleted事件回调,是吗?

XAML has some "similar" functionality using: ManipulationStarted,  ManipulationDelta, ManipulationCompleted event callbacks, yes?

我想重新定位Canvas上的对象(X,Y)位置。我不想在Visual Tree中重新定位对象位置,虽然这也很有用。 

I want to reposition an objects (X,Y) location on the Canvas. I do not want to reposition an objects position within the Visual Tree, although this is useful too. 

我设置了 ScrollView '事件回调'使用 ScrollView.ViewChanging + = OnScrollViewChanging 。回调传递下一个Canvas左侧,顶部位置。不太理想,但是当用户使用滚动条缩略图调整ScrollView
时,这似乎有效。到目前为止,这似乎运作良好(有限的测试)。回调似乎与渲染'管道''同步'。

I set a ScrollView 'event callback' using ScrollView.ViewChanging += OnScrollViewChanging. The callback passes the next Canvas left, top position. Not ideal, but this seems to work when the user adjusts the ScrollView using scrollbar thumbnails. This seems to work well so far (limited testing). The callback seems to be 'sync' with the rendering 'pipeline'.

当用户滚动ScrolView $ b $时,这不能正常工作 b使用鼠标滚轮

This does not work well when the user scrolls the ScrolView using the mouse wheel.

我也试过鼠标滚轮PointerWheelChanged,但这个'事件回调'似乎不起作用。它似乎不像滚动条那样经常被回叫,因此对象显示"类别7抖动"。在人行道上形成裂缝,b $ b砖,块,玻璃落在建筑物等处。对用户行人来说不好。

I also tried the mouse wheel PointerWheelChanged for example, but this 'event callback' doesn't seem to work. It does not 'seem' to be called back as often as the scrollbars, so the object displays "Category 7 Jitter". Cracks form in the pavement, bricks, blocks, glass is falling down of building, etc. Not good for user-pedestrians.

我不知道同步正在回调的事件。我不知道它们与渲染管道同步的程度如何,或者它们是否同步。 

I don't know of the synchronization of the events being called back. I don't know how well they are synced with the rendering pipeline or if they are synced at all. 

我想附加一个事件处理程序,以自定义一些渲染元素,并非所有,渲染管道。通过根目录树或特定的可视容器附加它。 

I would like to attach an event handler, to customize some rendering elements, not all, to the rendering pipeline. Either attached it via the root visual tree or a specific visual container. 

目前,禁用鼠标滚轮更改事件会有所帮助。它会阻止抖动。 

For the time being, disabling the mouse wheel change event would help. It would stop the Jitter. 

感谢您的任何反馈,非常感谢,

Any feedback is appreciated, thank you so much,

Mark

推荐答案

欢迎
到开发通用Windows应用论坛!
 

Welcome to the Developing Universal Windows apps forum! 

你的项目类型是什么?

请阅读粘贴帖子,尤其是

发布指南:subject li ne标签

Windows 10 SDK和工具的已知问题 
 并自行为标题添加标记。

Please read the sticky posts, especially theGuide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools  and add tag to title by yourself.

您可以考虑注册
LayoutUpdated
事件。当可视树的布局发生变化时,由于布局相关属性更改值或其他一些刷新布局的操作,会发生此事件。

You could think about registering LayoutUpdated event for your ScrollViewer. This event Occurs when the layout of the visual tree changes, due to layout-relevant properties changing value or some other action that refreshes the layout.

最诚挚的问候,

Xavier Eoro

Xavier Eoro


这篇关于[UWP] [C#] [Visual Tree] [渲染管道]如何在渲染过程中使用根Visual Tree或Visual Tree元素注册回调事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:03