Wpf 在StackPanel周围设置边框。

Wpf 在StackPanel周围设置边框。,wpf,orientation,stackpanel,Wpf,Orientation,Stackpanel,以下是我的XAML代码: <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" Wid

以下是我的XAML代码:

<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的右侧,而不是添加到它下面。原因是什么?

您将DockPanel.Dock=“Top”设置为StackPanel,但StackPanel不是DockPanel的子项。。。边界很窄。您的停靠属性将被忽略

如果您将DockPanel.Dock=“Top”移到边框,两个问题都会得到解决:)

这一个呢:

<DockPanel Margin="8">
    <Border CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="2" DockPanel.Dock="Top">
        <StackPanel Orientation="Horizontal">
            <TextBlock FontSize="14" Padding="0 0 8 0" HorizontalAlignment="Center" VerticalAlignment="Center">Search:</TextBlock>
            <TextBox x:Name="txtSearchTerm" HorizontalAlignment="Center" VerticalAlignment="Center" />
            <Image Source="lock.png" Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center" />            
        </StackPanel>
    </Border>
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" Height="25" />
</DockPanel>

搜索:

可能会有帮助:

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="160" Margin="10,55,0,0" VerticalAlignment="Top" Width="492"/>


在桌面WPF应用程序DockPanel中,边框元素不存在:(为什么?@usernamehahahahahahahaha
DockPanel
本身就是一个元素,您可以将其他元素添加到其中。它不是
Border
的属性,因为您不会停靠边框-它围绕一个对象,而不是停靠在一个对象上,就像您可以如何操作
,从而有效地“停靠”堆栈面板(第节)靠着船坞面板的顶部(拱形容器)。我的孩子!酷!!!