---
title: "ScrollViewer control in WPF"  
description: "In XAML ScrollViewer  element is used to create a scroll viewer control in WPF. Scroll viewer control responds to both mouse and keyboard commands and"  
author: "Anonymous User"  
published: 2011-04-06  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/538/scrollviewer-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# ScrollViewer control in WPF

In XAML <ScrollViewer /> element is used to create a scroll viewer [control](https://yourviews.mindstick.com/view/83439/bipartisan-gun-control-bill-passed-in-us-after-decades) in WPF. Scroll viewer control responds to both mouse and [keyboard](https://www.mindstick.com/forum/23117/android-soft-keyboard-close-hide) [commands](https://www.mindstick.com/interview/817/what-is-the-use-of-dbcc-commands) and defines numerous [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) with which to scroll [content](https://www.mindstick.com/articles/12369/cms-extension-for-magento-2-advanced-content-manager-2) by predetermined increments. A scroll viewer control can have one child, typically a [panel](https://www.mindstick.com/blog/11988/restructuring-corporate-offenses-government-appointed-panel-suggests-in-house-adjudication-system) [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) that can host a [children](https://yourviews.mindstick.com/view/81386/mobile-app-based-education-curse-or-boon-for-our-children) [collection](https://www.mindstick.com/articles/1718/collections-in-java) of elements. The content [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) defines sole child of the Scroll Viewer. We can use scroll viewer control for those control which does not provide scrolling functionality.\

##### The following XAML code snippets represent use of ScrollViewer control

```
<Grid>        <Grid.RowDefinitions>            <RowDefinition />            <RowDefinition Height="30"/>        </Grid.RowDefinitions>        <Grid.ColumnDefinitions>            <ColumnDefinition />        </Grid.ColumnDefinitions>        <ScrollViewer Grid.Row="0" Grid.Column="0"   HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">            <Image x:Name="imgSource" />        </ScrollViewer>        <Button x:Name="btnLoadImage" Grid.Column="0" Grid.Row="1" Content="Load Image" Width="200" Height="30" Click="btnLoadImage_Click" /></Grid>  
```

##### Business logic of this demonstration

```
/// <summary>        /// On the click event of browse image button a open file        /// dialog box opens and we browse the image that we needs        /// to open        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>          private void btnLoadImage_Click(object sender, RoutedEventArgs e)        {            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();            if (ofd.ShowDialog().Value)            {                string fileName = ofd.FileName;                BitmapImage img = new BitmapImage();                img.BeginInit();                img.UriSource = new Uri(fileName);                img.EndInit();                imgSource.Source = img;            }        }
```

##### Output of the following code snippet is as follows

![ScrollViewer control in WPF](https://www.mindstick.com/mindstickarticle/ff70321a-f364-44c6-818d-10272b68b053/images/ee811388-0015-477d-bbca-db1e513a16b7.png)

When user click on Load image button then an open file dialog box opens and user select image and then click Open button and then image is loaded.

![ScrollViewer control in WPF](https://www.mindstick.com/mindstickarticle/ff70321a-f364-44c6-818d-10272b68b053/images/d5f609c1-691f-48d0-8bf2-7fc9ebab9610.png)

---

Original Source: https://www.mindstick.com/articles/538/scrollviewer-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
