WPF - StackPanel 的问题

标签 wpf

我是 WPF 的新手,我无法弄清楚一些事情。我刚开始一个新项目,我想制作一个 StackPanel,因为我在教程中看到了它。但是现在我已经实现了 StackPanel 并且出现了 2 个错误。

The object 'Window' already has a child and cannot add 'StackPanel'. 'Window' can accept only one child. Line 9 Position 116.

The property 'Content' is set more than once.

有人可以向我解释我做错了什么吗? 这是我的代码:

<Window x:Class="CheckDatabase.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CheckDatabase" Height="350" Width="525">
<Grid Margin="10,80,10,10" >
    <TextBox TextWrapping="Wrap"/>
</Grid>

<StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Name="ButtonPanel" VerticalAlignment="Top">
    <Button Margin="0,10,0,10">Button 1</Button>
    <Button Margin="0,10,0,10">Button 2</Button>
</StackPanel>

提前致谢

最佳答案

一个 Window 只能包含一个 child 。但是,您的 Window 包含 GridStackPanel

要解决此问题,您需要将 StackPanel 放在网格内(如果有此意图)或同时包裹 GridStackPanel 在另一个面板内,以您想要的方式放置两个元素。

关于WPF - StackPanel 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19629643/

相关文章:

c# - 当鼠标在弹出窗口外单击时如何防止弹出窗口关闭

c# - DataGrid SortDirection 被忽略

c# - 如何从 WPF TextBlock 中删除额外的填充?

wpf - 容器内的隐式样式

wpf - 停止 WPF ScrollViewer 自动滚动到感知的内容

wpf - 有没有办法将命令与 WPF 工具包 DataGridHyperlinkColumn 相关联?

c# - 如何在 WPF WebView2 中禁用 CORS

c# - WPF UI 在事件触发时挂起

wpf - 在(主要)无窗口 WPF 应用程序中将代码放在哪里?

wpf - 如何在 appxmanifest 中自动提供版本?