如何让 ScrollViewer 在子级执行 RenderTransform 后更新其布局?

发布于 2024-12-28 18:42:57 字数 1487 浏览 2 评论 0原文

我有一个 ScrollViewer,在其中使用 Blend 控件 PathListBox,我使用 RenderTransfrom 来旋转和缩放其子控件。

不幸的是, ScrollViewer 的大小与我的 Ellispe (我用作路径的控件)的大小相同,我不知道如何获取 ScrollViewer 的 视口包含整个控件(所有 PathListBoxItem)。

我认为它无法调整到 PathListBox 的完整大小的原因是我的 RenderTransform< /代码>,但我尝试用 LayoutTransform 替换它,它仍然会删除一些内容(虽然没那么糟糕,但 LayoutTransform 不是我需要的)。

我的 Xaml 看起来像这样(为了简单起见,我省略了一些内容):

<ScrollViewer>
    <Grid>
        <Ellipse ... />
        <ec:PathListBox ...>
            <ec:PathListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="-90" />
                                <TranslateTransform X="{Binding ...}"
                            </TransformGroup>
                        <Grid.RenderTransform>
                        <Rectangle ... />
                    </Grid>
                </DataTemplate>
            </ec:PathListBox.ItemTemplate>
            <ec:PathListBox.LayoutPaths>
                <ec:LayoutPath SourceElement="{Binding ElementName=ellipse}" ... />
            </ec:PathListBox.LayoutPaths>    
        </ec:PathListBox>
    </Grid>
</ScrollViewer>

I have a ScrollViewer and within it I use the Blend control PathListBox, whose children I rotate and scale with a RenderTransfrom.

Unfortunately, the ScrollViewer sizes to the size of my Ellispe (the control that I'm using as my path) and I can't figure out how to get ScrollViewer's viewport to include the entire control (all the PathListBoxItems.)

I thought the reason it wouldn't size to the complete size of my PathListBox was because of my RenderTransform, but I tried replacing it with a LayoutTransform and it still cuts out stuff (not as bad though, but a LayoutTransform is not what I need).

My Xaml looks something like this (for the sake of simplicity I left some stuff out):

<ScrollViewer>
    <Grid>
        <Ellipse ... />
        <ec:PathListBox ...>
            <ec:PathListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="-90" />
                                <TranslateTransform X="{Binding ...}"
                            </TransformGroup>
                        <Grid.RenderTransform>
                        <Rectangle ... />
                    </Grid>
                </DataTemplate>
            </ec:PathListBox.ItemTemplate>
            <ec:PathListBox.LayoutPaths>
                <ec:LayoutPath SourceElement="{Binding ElementName=ellipse}" ... />
            </ec:PathListBox.LayoutPaths>    
        </ec:PathListBox>
    </Grid>
</ScrollViewer>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ人海孤独症 2025-01-04 18:42:57

RenderTranforms 不影响布局。从此处

渲染转换不会重新生成布局大小或渲染大小信息。渲染变换通常用于对元素进行动画处理或应用临时效果。例如,元素可能会在聚焦或鼠标悬停时缩放,或者可能在加载时抖动以将注意力吸引到用户界面 (UI) 的该部分。

你想要的是一个 LayoutTransform。从此处

与RenderTransform相比,LayoutTransform会影响布局的结果。

LayoutTransform 有用的示例场景包括:将菜单组件等元素从水平旋转到垂直,反之亦然,缩放焦点上的元素(放大),提供编辑行为等。

听起来您使用了错误的布局元素(除了使用错误的转换之外),但很难说,因为你实际上并没有说出你想要做什么。当您执行 LayoutTransform 时它仍然会切断内容的原因可能是因为没有足够的空间让项目在可用空间中完全呈现。

编辑:

提供我建议使用自定义面板类型的附加信息:“径向”面板。示例此处这里

RenderTranforms don't affect the layout. From here:

A render transform does not regenerate layout size or render size information. Render transforms are typically intended for animating or applying a temporary effect to an element. For example, the element might zoom when focused or moused over, or might jitter on load to draw the eye to that part of the user interface (UI).

What you want is a LayoutTransform. From here:

In contrast to RenderTransform, LayoutTransform will affect results of layout.

and

Example scenarios where LayoutTransform would be useful include: rotating elements such as menu components from horizontal to vertical or vice versa, scaling elements (zooming in) on focus, providing editing behavior, etc.

It sounds like you're using the wrong layout element (in addition to using the wrong transform), but it's difficult to tell since you don't actually say what you want to do. The reason it was still cutting stuff off when you did a LayoutTransform was probably because there wasn't enough space for the items to render completely in the available space.

Edit:

Give the additional information I would suggest using a custom panel type: the "radial" panel. Examples here and here.

梓梦 2025-01-04 18:42:57

我暂时实施了一个黑客来掩盖问题。不过,我仍在寻找更正确的方法来解决问题。 :)

我在网格中添加了一个透明的矩形,并使其宽度等于椭圆的大小 + 已转换的 PathListBoxItems 的(长度)大小。

滚动区域现在允许我滚动到之前剪切的区域。

编辑:我将暂时将此标记为答案,因为它确实有效。我只是觉得这不是最好的解决方案,所以我愿意将另一个答案标记为正确。

I implemented a hack for the time being that masks the problem. I'm still looking for a more correct approach to fixing the problem though. :)

I added a transparent Rectangle to the grid and made it's width equal to the size of the Ellipse + the size of (length) PathListBoxItems that were transformed.

The scroll area now allows me to scroll to areas that were previously clipped.

EDIT: I'll mark this as the answer for the time being since it does work. I just don't feel like this is the best solution so I'll be willing to mark another answer as correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文