我在调整 WPF 中 Grid
内的 Canvas
时遇到问题。我希望它与 Grid
的 Right
和 Top
边有 10px 的边距。我在下面的代码中做错了什么?
<Window x:Class="Layout2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="DrawingArea" Background="Black">
<Canvas x:Name="InformationLayer"
Background="White"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Right="10"
Top="10"
Width="200" Height="30" >
</Canvas>
</Grid>
</Window>
最佳答案
Right
和 Top
是 Canvas
类的附加属性,它们将元素定位在父级 Canvas
对象中.我不认为它们在 Canvas
标记本身中使用时具有语义意义(当然除非您嵌套在 Canvas 中)。
相反,使用边距属性:
<Canvas x:Name="InformationLayer"
Background="White"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,10,10,0"
Width="200" Height="30" >
</Canvas>
边距的格式为“左、上、右、下”,以备您需要修改!
关于c# - 在 WPF 中调整网格内的 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23743917/