50

これが私の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の右側に追加されます。これの理由は何ですか?

4

3 に答える 3

41

これはどうですか :

<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>
于 2010-04-18T17:14:41.757 に答える
20

DockPanel.Dock = "Top"をStackPanelに設定しましたが、StackPanelはDockPanelの子ではありません...境界線はです。ドッキングプロパティは無視されます。

代わりにDockPanel.Dock="Top"をBorderに移動すると、両方の問題が修正されます:)

于 2010-04-18T17:13:16.227 に答える
5

それが役立つかもしれません:

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="160" Margin="10,55,0,0" VerticalAlignment="Top" Width="492"/>
于 2019-11-06T12:16:32.837 に答える