Raise the ScrollChanged event of a ScrollViewer : ScrollViewer « Windows Presentation Foundation « VB.Net






Raise the ScrollChanged event of a ScrollViewer

Raise the ScrollChanged event of a ScrollViewer
      


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ScrollChangedEventArgs_layout.Window1"
    Title="ScrollChangedEventArgs Sample">
  <ScrollViewer>
    <Border BorderBrush="Black" BorderThickness="2" Background="White">
      <StackPanel HorizontalAlignment="Left" Margin="10">
        <TextBlock FontSize="20" FontWeight="Bold">
          ScrollChangedEvent Sample<LineBreak/>
        </TextBlock>
        <TextBlock Margin="0,0,0,15">Use the ScrollBar to activate the ScrollChanged event.</TextBlock>
        <Button Name="btn1" Click="scrollTrue">Enable Content Scrolling</Button>
        <ScrollViewer Name="sv1" CanContentScroll="False" ScrollChanged="sChanged">
          <FlowDocument FontFamily="Arial" PageWidth="400">
            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>
            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>

            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>

            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>

            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>
            <Paragraph>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
              laoreet dolore magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis nostrud exerci tation
              ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
            </Paragraph>

          </FlowDocument>
        </ScrollViewer>
      </StackPanel>
    </Border>
  </ScrollViewer>
</Window>


//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents

Namespace ScrollChangedEventArgs_layout
  Public Partial Class Window1
    Inherits Window
    Public Sub scrollTrue(sender As Object, e As RoutedEventArgs)
      sv1.CanContentScroll = True
      sv1.Height = 600
      btn1.Visibility = Visibility.Collapsed
    End Sub
    Public Sub sChanged(sender As Object, e As ScrollChangedEventArgs)
      If sv1.CanContentScroll = True Then
        Console.WriteLine("ScrollChangedEvent just Occurred")
        Console.WriteLine("ExtentHeight is now " & e.ExtentHeight.ToString())
        Console.WriteLine("ExtentWidth is now " & e.ExtentWidth.ToString())
        Console.WriteLine("ExtentHeightChange was " & e.ExtentHeightChange.ToString())
        Console.WriteLine("ExtentWidthChange was " & e.ExtentWidthChange.ToString())
        Console.WriteLine("HorizontalOffset is now " & e.HorizontalOffset.ToString())
        Console.WriteLine("VerticalOffset is now " & e.VerticalOffset.ToString())
        Console.WriteLine("HorizontalChange was " & e.HorizontalChange.ToString())
        Console.WriteLine("VerticalChange was " & e.VerticalChange.ToString())
        Console.WriteLine("ViewportHeight is now " & e.ViewportHeight.ToString())
        Console.WriteLine("ViewportWidth is now " & e.ViewportWidth.ToString())
        Console.WriteLine("ViewportHeightChange was " & e.ViewportHeightChange.ToString())
        Console.WriteLine("ViewportWidthChange was " & e.ViewportWidthChange.ToString())
      End If
    End Sub
  End Class
End Namespace

   
    
    
    
    
    
  








Related examples in the same category

1.Add StackPanel to ScrollViewerAdd StackPanel to ScrollViewer
2.Display Content in a Scrollable User InterfaceDisplay Content in a Scrollable User Interface
3.Hidden ScrollViewerHidden ScrollViewer
4.Use the content-scrolling methods of the ScrollViewer classUse the content-scrolling methods of the ScrollViewer class
5.Create a scroll viewer using the ScrollViewer element.Create a scroll viewer using the ScrollViewer element.
6.Scroll Viewer and stack panelScroll Viewer and stack panel