简体   繁体   English

在WPF视图框中对齐内容

[英]Aligning content in a WPF Viewbox

I have a Viewbox with Stretch=Uniform in order to not distort the content. 我有一个带Stretch=Uniform的Viewbox,以免扭曲内容。 However, when the frame window is wider or taller than the content, the Viewbox content is always centered. 但是,当框架窗口比内容更宽或更高时,Viewbox内容始终居中。

I cannot seem to find any content alignment options on the Viewbox. 我似乎无法在Viewbox上找到任何内容对齐选项。 Is there a way to do this? 有没有办法做到这一点?

Try VerticalAlignment="Top" and HorizontalAlignment="Left" on your viewbox. 在视图框上尝试VerticalAlignment="Top"HorizontalAlignment="Left" It will cause it to be anchored to the top and left side. 它会使它锚定在顶部和左侧。

<Grid>
    <Viewbox VerticalAlignment="Top" HorizontalAlignment="Left">
    ...
    </Viewbox>
</Grid>

If you want it to completely fill (but keep it uniform) you can use Stretch="UniformToFill" 如果你想要它完全填充(但保持统一)你可以使用Stretch="UniformToFill"

According to MSDN the Viewbox is used to stretch the child elements. 根据MSDN ,Viewbox用于拉伸子元素。 Since the child elements would be stretched, you would have to set the content alignment of the children. 由于子元素将被拉伸,因此您必须设置子元素的内容对齐方式。

You may want to look at this for more information on the Viewbox: How do I keep aspect ratio on scalable, scrollable content in WPF? 您可能需要查看此信息以获取有关Viewbox的更多信息: 如何在WPF中保持可伸缩,可滚动内容的宽高比?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM