如何让 ScrollViewer 在子级执行 RenderTransform 后更新其布局?
我有一个 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 PathListBoxItem
s.)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RenderTranforms 不影响布局。从此处:
你想要的是一个 LayoutTransform。从此处:
和
听起来您使用了错误的布局元素(除了使用错误的转换之外),但很难说,因为你实际上并没有说出你想要做什么。当您执行 LayoutTransform 时它仍然会切断内容的原因可能是因为没有足够的空间让项目在可用空间中完全呈现。
编辑:
提供我建议使用自定义面板类型的附加信息:“径向”面板。示例此处和这里。
RenderTranforms don't affect the layout. From here:
What you want is a LayoutTransform. From here:
and
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.
我暂时实施了一个黑客来掩盖问题。不过,我仍在寻找更正确的方法来解决问题。 :)
我在网格中添加了一个透明的矩形,并使其宽度等于椭圆的大小 + 已转换的 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.