gpt4 book ai didi

c# - 如何在 xaml WPF 中的堆栈面板或网格上设置绝对位置

转载 作者:技术小花猫 更新时间:2023-10-29 11:05:51 24 4
gpt4 key购买 nike

是否可以将我的 StackPanel 或 Grid 设置为像 CSS 一样的绝对位置。在 CSS 中有元素的属性 Position 并且可以设置为相对的,绝对的并且工作良好。

在XAML中可以让Grid、StackPanel使用position absolute。

最佳答案

您必须使用 Canvas 才能在 WPF 中设置绝对位置。

如果是窗口中的按钮,这里是一个示例:

<Window x:Class="tobedeleted.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Canvas>
<Button Canvas.Left="10" Canvas.Bottom="20">Bottom left</Button>
</Canvas>
</Window>

输出是:

enter image description here

如果需要帮助,请随时询问。

关于c# - 如何在 xaml WPF 中的堆栈面板或网格上设置绝对位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35064843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com