2010-06-07 3 views
1

버튼이있는 스택 패널과 스크롤바가없는 WPF ScrollViewer를 사용하려고합니다.WPF ScrollViewer에서 하위 컨트롤 자르기를 확인하려면 어떻게해야합니까?

<ScrollViewer Grid.Row="1" Name="scrollViewer1" VerticalScrollBarVisibility="Hidden"> 
     <StackPanel Name="stackPanel1"> 
      <Button Content="Button1" Height="23" Name="button1" MinHeight="75" /> 
      <Button Content="Button2" Height="23" Name="button2" MinHeight="75" /> 
      <Button Content="Button3" Height="23" Name="button3" MinHeight="75" /> 
      <Button Content="Button4" Height="23" Name="button4" MinHeight="75" /> 
      <Button Content="Button5" Height="23" Name="button5" MinHeight="75" /> 
     </StackPanel> 
    </ScrollViewer> 

내가 창에서 다른 곳 "아래로 스크롤" "스크롤"버튼을 사용하려면 (이 차량 화면에 작은에 사용 될 가능성이있다). scrollViewer1.LineDown() 등을 사용하여 쉽게 할 수 있지만 뷰포트 밖으로 또는 요소가 잘린 경우에만 "스크롤 업/스크롤 다운"버튼을 표시하고 싶습니다.

여기서 시작하는 방법을 모르겠습니다. 각 요소를 테스트해야합니까?

모든 안내를 환영합니다! 이 코드는 활성화/위 아래로 버튼이 비활성화됩니다

안부, 제이슨

답변

0

.

XAML :

<Window x:Class="ScrollTest.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="300" Width="300"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <ScrollViewer Grid.Row="0" ScrollChanged="OnScrollChanged"> 
      <StackPanel> 
       <Button Content="Button1" Height="50" /> 
       <Button Content="Button2" Height="50" /> 
       <Button Content="Button3" Height="50" /> 
       <Button Content="Button4" Height="50" /> 
       <Button Content="Button5" Height="50" /> 
      </StackPanel> 
     </ScrollViewer> 
     <Button Grid.Row="1" Name="_upButton" Content="Up" /> 
     <Button Grid.Row="2" Name="_downButton" Content="Down" /> 
    </Grid> 
</Window> 

코드 숨김

매우 빠른 회신
+0

많은 감사

private void OnScrollChanged(object sender, ScrollChangedEventArgs e) { _upButton.IsEnabled = (sender as ScrollViewer).VerticalOffset > 0; _downButton.IsEnabled = (sender as ScrollViewer).VerticalOffset < (sender as ScrollViewer).ScrollableHeight; } 
이 - 완벽하게 법안을 맞는! –

관련 문제