gpt4 book ai didi

xaml - WPF中的QT间隔等效

转载 作者:行者123 更新时间:2023-12-04 08:49:13 29 4
gpt4 key购买 nike

我有一个带有一些垂直对齐控件的 StackPanel(这张图片右侧的堆栈面板:
enter image description here

最后一个控件应始终放置在边框控件内部的窗口底部(图片上的确定按钮)。在 QT 中,我会插入一个间隔控件来按下按钮。我如何在 WPF 中做到这一点?谢谢你。这是xaml:

<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="354*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Border Margin="5" Background="Gray" CornerRadius="6" BorderBrush="Gray">
<Viewport3D Grid.Column="0" Name="viewport" ClipToBounds="True">
</Viewport3D>
</Border>

<Border Grid.Column="1" CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="1" Margin="5" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Stretch" >
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Dimension" Name="label1" VerticalAlignment="Center" />
<ComboBox Text="3D" HorizontalAlignment="Right" Name="dimensioncb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
<ComboBoxItem>2D</ComboBoxItem>
<ComboBoxItem>3D</ComboBoxItem>
</ComboBox>
</StackPanel>
<Separator/>
<DockPanel>
<Label Content="Iteration" Name="label2" VerticalAlignment="Center" />
<ComboBox Text="3" HorizontalAlignment="Right" Name="iterationcb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
</ComboBox>
</DockPanel>
<Button Content="OK" VerticalAlignment="Bottom"/>
</StackPanel>
</Border>

</Grid>
</Window>

最佳答案

有很多方法可以在 WPF 中完成此操作。下图是其中之一:

<Border Grid.Column="1" CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="1" Margin="5" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Stretch" >
<!--Add a grid control to separate your stackpanel and button-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<StackPanel Orientation="Horizontal">
<Label Content="Dimension" Name="label1" VerticalAlignment="Center" />
<ComboBox Text="3D" HorizontalAlignment="Right" Name="dimensioncb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
<ComboBoxItem>2D</ComboBoxItem>
<ComboBoxItem>3D</ComboBoxItem>
</ComboBox>
</StackPanel>
<Separator/>
<DockPanel>
<Label Content="Iteration" Name="label2" VerticalAlignment="Center" />
<ComboBox Text="3" HorizontalAlignment="Right" Name="iterationcb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
</ComboBox>
</DockPanel>
</StackPanel>
<Button Grid.Row="1" Content="OK" VerticalAlignment="Bottom"/>
</Grid>
</Border>

上面的XAML,用来替换右边的 Border在您的 XAML 中将产生以下结果,并在调整窗口大小时将按钮保留在底部。

enter image description here

关于xaml - WPF中的QT间隔等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18701585/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com