2014-04-19 4 views
3

을 스택 패널에 넣습니다. 런타임시 코드의 일부 레이블을 추가합니다. 스택 패널을 스크롤 가능하게 만들고 싶습니다. 내가 StackPanel의 일부 레이블을 추가 뒤에 코드에서WPF 어떻게 StackPanel Scrollable을 만들 수 있습니까?

<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> 

을 : XAML 파일에서 나는이

for(.....) 
{ 
    stackPanelVistaProfiloTessera.Children.Add(new Label {....}); 
} 

StackPanel의 스크롤없는 이유는 무엇입니까? 어떻게 해결할 수 있습니까? stackpanel..rest에서

감사

+0

'StackPanel' 안에'ScrollViewer'를 넣으십시오. –

+0

대신 ListBox를 사용할 수 있습니다. 자동으로 스크롤됩니다. – Johan

답변

9

제거 높이와 폭은 여기에 잘 작동한다.

<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> 

출력은 다음과 같습니다.

enter image description here

당신은 당신이 디자인 용도로 높이와 너비를 사용하는 경우 StackPanel을 위해 마진을 설정할 수 있습니다.

+0

그것은 작동한다, 감사 – Tom

+0

당신은 환영 받다. –

관련 문제