ARTICLE

ScrollViewer control in WPF using VB.NET

Posted by Rohatash Kumar Articles | WPF using VB.NET January 11, 2011
In this article we will learn how to use ScrollViewer control in WPF.
 
Reader Level:

In this article we will learn how to use ScrollViewer control in WPF.

ScrollViewer control

ScrollViewer control Represents a scrollable area that can contain other visible elements. Suppose an image which has the large size and Image control alone would not be sufficient to display the content of the picture. only part of it would be visible in the UI. To see the entire image you need a control that can allow you to scroll, either horizontally, or vertically or in both directions.

Properties: These are the following properties of the ScrollViewer control.

sv2.gif

Figure 1.

HorizontalScrollBarVisibility - This property is used to indicates whether a horizontal ScrollBar should be displayed.

VerticalScrollBarVisibility - This property is used to indicates whether a Vertical ScrollBar should be displayed.

Width - Gets or sets the width of a ScrollViewer control.

Height - Gets or sets the height of a ScrollViewer control.

Foreground - This property is used to describes the foreground color.

Creating ScrollViewer control in XAML

<ScrollViewer Height="31" HorizontalAlignment="Left" Margin="10,10,0,0" Name="ScrollViewer1" VerticalAlignment="Top" Width="124" />

The ScrollViewer control looks like this.

sv1.gif

Figure 2.

For example:

Drag and drop the ScrollViewer control and an Image control from the Toolbox on the form. The form looks like this.

sv3.gif

Figure 3.

XAML Code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid Width="579">

        <ScrollViewer Height="200" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" Margin="143,26,229,85">

            <Image Stretch="Fill" Width="395" Height="254" Name="Image1">

            </Image>

        </ScrollViewer>

    </Grid>

</Window>

 

Now select image control and set the source property.

 

<Image Stretch="Fill" Width="395" Height="254" Name="Image1" Source="/WpfApplication3;component/Images/dog-animal.jpg">

</Image>

 

Now build the Application.


sv4.gif 

Figure 4.

 

Image after scrolling horizontally:


sv5.gif 

Figure 5.

 

Image after scrolling vertically:


sv6.gif 

Figure 6.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Diagram
Become a Sponsor