我是 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
包含 Grid
和 StackPanel
。
要解决此问题,您需要将 StackPanel
放在网格内(如果有此意图)或同时包裹 Grid
和 StackPanel
在另一个面板内,以您想要的方式放置两个元素。
关于WPF - StackPanel 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19629643/