我无法在 WPF 中调整Canvas内部Grid。我希望它有从10px的保证金Right和Top两侧Grid。我在下面的代码中做错了什么?
<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>
Run Code Online (Sandbox Code Playgroud)

Right和Top是Canvas在父Canvas对象中定位元素的类的附加属性。我不相信它们在Canvas标签本身中使用时具有语义含义(当然,除非您嵌套在画布中)。
相反,使用 margin 属性:
<Canvas x:Name="InformationLayer"
Background="White"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,10,10,0"
Width="200" Height="30" >
</Canvas>
Run Code Online (Sandbox Code Playgroud)
边距格式为“左、上、右、下”,以防您需要修改!