列表未填充堆栈面板中的最大空间
我有以下代码,我认为列表应该填充堆栈面板占用的整个空间,我尝试使用网格但它不起作用。
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" DockPanel.Dock="Top">
<ListBox x:Name="substanceList" ItemsSource="{Binding Source={StaticResource symTable}}" DockPanel.Dock="Top" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=TwoWay}" VerticalAlignment="Center"/>
<TextBox Text="{Binding Count, Converter={StaticResource stringToIntConverter}, Mode=TwoWay}" VerticalAlignment="Center" BorderThickness="0"/>
<Separator/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="graphButtonStackPanel" Content="Graph" Click="graphButtonStackPanel_Click" DockPanel.Dock="Top" HorizontalAlignment="Right"/>
</StackPanel>
I have the following code, I think the List should fill out the entire space occupied by the stack panel, I tried using Grid but it didn't work.
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" DockPanel.Dock="Top">
<ListBox x:Name="substanceList" ItemsSource="{Binding Source={StaticResource symTable}}" DockPanel.Dock="Top" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=TwoWay}" VerticalAlignment="Center"/>
<TextBox Text="{Binding Count, Converter={StaticResource stringToIntConverter}, Mode=TwoWay}" VerticalAlignment="Center" BorderThickness="0"/>
<Separator/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="graphButtonStackPanel" Content="Graph" Click="graphButtonStackPanel_Click" DockPanel.Dock="Top" HorizontalAlignment="Right"/>
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
StackPanels
堆叠事物,如果您希望拉伸内容,请使用Grid
。例如StackPanels
stack things, if you want your content stretched use aGrid
. e.g.堆栈面板会根据其内容进行扩展,而不是相反。
可能只是没有足够的内容来填充您的可用空间。
Stack panels grow to fit their content, not the other way round.
It could just be that there isn't enough content to fill your available space.