本文介绍了在StackPanel周围设置边框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的XAML代码:
Here's my XAML code:
<Window x:Class="CarFinder.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Search for cars in TuMomo" Height="480" Width="600">
<DockPanel Margin="8">
<Border CornerRadius="6"
BorderBrush="Gray"
Background="LightGray"
BorderThickness="2"
Padding="8">
<StackPanel Orientation="Horizontal"
DockPanel.Dock="Top"
Height="25">
<TextBlock FontSize="14" Padding="0 0 8 0">
Search:
</TextBlock>
<TextBox x:Name="txtSearchTerm" Width="400" />
<Image Source="/CarFinder;component/Images/Chrysanthemum.jpg" />
</StackPanel>
</Border>
<StackPanel Orientation="Horizontal"
DockPanel.Dock="Top"
Height="25">
</StackPanel>
</DockPanel>
</Window>
在整个窗口周围设置边框.而且,当我创建另一个StackPanel时,它会添加到我以前的StackPanel的右侧,而不是添加到它的下面.是什么原因呢?
The border is set around the entire window. And also, when I create another StackPanel it's added to the right of my previous StackPanel instead of being added under it. What's the reason for this?
推荐答案
您将DockPanel.Dock ="Top"设置为StackPanel,但是StackPanel不是DockPanel的子代...边框是.您的对接属性将被忽略.
You set DockPanel.Dock="Top" to the StackPanel, but the StackPanel is not a child of the DockPanel... the Border is. Your docking property is being ignored.
如果将DockPanel.Dock ="Top"移至Border,则两个问题都将得到解决:)
If you move DockPanel.Dock="Top" to the Border instead, both of your problems will be fixed :)
这篇关于在StackPanel周围设置边框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!