WPF如何做的StackPanel滚动 [英] WPF how make StackPanel Scrollable
本文介绍了WPF如何做的StackPanel滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个StackPanel中我添加从code一些标签后面在运行时:我想作的StackPanel滚动。 XAML文件中我有:
in a stackpanel i add some labels from code behind at runtime: i want make the stackpanel scrollable. In the xaml file i have:
<ScrollViewer HorizontalAlignment="Left" Height="299" Margin="592,120,0,0" VerticalAlignment="Top" Width="188" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="stackPanelVistaProfiloTessera" Height="292" Width="170"/>
</ScrollViewer>
在code后面我添加了一些标签的StackPanel的:
In the code behind i add some label to the stackpanel:
for(.....)
{
stackPanelVistaProfiloTessera.Children.Add(new Label {....});
}
为什么StackPanel中不可滚动?我该如何解决?
Why the stackpanel isn't scrollable? How can i resolve this?
感谢
推荐答案
删除高度和宽度从stackpanel..rest正在这里很好。
Remove height and width from stackpanel..rest is working fine here.
<ScrollViewer HorizontalAlignment="Left" Background="Green" Height="299" Margin="592,120,0,0" VerticalAlignment="Top" Width="188" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="stackPanelVistaProfiloTessera" Background="RoyalBlue" >
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
<Label Height="30" Width="100" Margin="5">label1</Label>
</StackPanel>
</ScrollViewer>
输出这个样子的。
Output look like this.
,你可以设置保证金,如果您使用的是高度和宽度的设计目的的StackPanel。
and you can set margin to stackpanel if you are using height and width for design purpose.
这篇关于WPF如何做的StackPanel滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文