为什么不是';我的容器是否占用WPF中的所有可用空间?
在下面的标记中,我在Scrollviewer中找到了标签。理想情况下,我不想让DockPanel在那里,但它在那里进行测试(它没有解决问题) 我希望Scrollviewer填满剩余的空间(将“发送电子邮件”按钮放在列的底部) 我做什么似乎无关紧要,我没办法做那该死的事为什么不是';我的容器是否占用WPF中的所有可用空间?,wpf,wpf-controls,Wpf,Wpf Controls,在下面的标记中,我在Scrollviewer中找到了标签。理想情况下,我不想让DockPanel在那里,但它在那里进行测试(它没有解决问题) 我希望Scrollviewer填满剩余的空间(将“发送电子邮件”按钮放在列的底部) 我做什么似乎无关紧要,我没办法做那该死的事 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="200" /> <ColumnDe
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<ComboBox ItemsSource="{Binding Campaigns}"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedCampaign}"
Text="Select a Campaign"/>
<ComboBox ItemsSource="{Binding Emails}"
DisplayMemberPath="Subject"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedEmail}"
Text="Select an Email"/>
<ComboBox ItemsSource="{Binding Groups}"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedGroup}"
Text="Select a Contact Group"/>
<Button Command="{Binding LoadContactsCommand}"
CommandParameter="{Binding SelectedGroup}"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
ToolTip="Refresh the current list of contacts." Content="Load Contacts"/>
<DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ScrollViewer DockPanel.Dock="Bottom" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Label Content="{Binding SendStatus, UpdateSourceTrigger=PropertyChanged}"
Height="auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</ScrollViewer>
</DockPanel>
<Button Command="{Binding SendEmailsCommand}" Content="Send Emails"
VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
</StackPanel>
</Grid>
如果希望某些元素垂直拉伸,请不要使用StackPanel。StackPanel可以为arrange提供无限的垂直空间,但拉伸到无限大是没有意义的,所以使用了尽可能小的尺寸 将网格与多个行定义一起使用,并将拉伸元素放置在具有
Height=“*”
的行中:
完美!谢谢:)我不知道为什么我没有想到它,但实际上它甚至比StackPanel看起来更好。
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding Campaigns}" Grid.Row="0"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedCampaign}"
Text="Select a Campaign"/>
<ComboBox ItemsSource="{Binding Emails}" Grid.Row="1"
DisplayMemberPath="Subject"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedEmail}"
Text="Select an Email"/>
<ComboBox ItemsSource="{Binding Groups}" Grid.Row="2"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsEditable="True" IsReadOnly="True"
SelectedItem="{Binding SelectedGroup}"
Text="Select a Contact Group"/>
<Button Command="{Binding LoadContactsCommand}" Grid.Row="3"
CommandParameter="{Binding SelectedGroup}"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
ToolTip="Refresh the current list of contacts." Content="Load Contacts"/>
<ScrollViewer Grid.Row="4" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Label Content="{Binding SendStatus, UpdateSourceTrigger=PropertyChanged}"
Height="auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</ScrollViewer>
<Button Grid.Row="5" Command="{Binding SendEmailsCommand}" Content="Send Emails"
VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
</Grid>