c# - 在 WPF 中调整网格内的 Canvas

标签 c# wpf canvas

我在调整 WPF 中 Grid 内的 Canvas 时遇到问题。我希望它与 GridRightTop 边有 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>

enter image description here

最佳答案

RightTopCanvas 类的附加属性,它们将元素定位在父级 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/

相关文章:

c# - 谁拥有放置在剪贴板上的 MemoryStream 对象? (或者应该使用 MemoryStream 以外的东西吗?)

c# - 从代码中获取 appSettings configSource

c# - 将 varbinary 从 sql 加载或转换为文本框文本?

c# - 必须在与 DependencyObject 相同的线程上创建 DependencySource

wpf - 提取正在运行的WPF应用程序的WPF内容模板

c# - 如何从同一个类中的静态函数调用公共(public)事件?

javascript - HTML 5 图像悬停调整大小和重定向

c# - 如何在 STAThread 模式下运行单元测试?

javascript - Sketch.js 将 Canvas 复制到剪贴板

javascript - 错误-使用Javascript和HTML Canvas 制作鼠标事件绘制功能