Pages

Tuesday 12 March 2013

ScrollViewer Control In WPF

ScrollViewer Control In WPF Window Based

WPF provides a ScrollViewer control that is a container for other controls and creates a scrollable area. It is simple to create and add to a XAML file. The developer can choose to display a horizontal and/or vertical scroll bar. For this article, I chose to hide the scoll bar so that the user must scroll by clicking on the content in the ScrollViewer..In WPF scrolling or you can say the ScrollViewer is used when we want to fit the large amounts of content in a limited amount of space. The ScrollViewer control provides a convenient way to enable scrolling of content in WPF. ScrollViewer encapsulated the ScrollBars within it and displays it whenever it is required. As the ScrollViewer implements IScrollInfo is the main scrolling area inside the scrollviewer. ScrollViewer also responds to mouse and keyboard commands.
 
Syntax of  ScrollViewer:

<ScrollViewer HorizontalScrollBarVisibility="Visible" >
</ScrollViewer>
 
Example:




XAML Code-

<Window x:Class="WpfApplication7.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="370" Width="417">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Visible" >
            <Grid Background="Aqua">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" MinWidth="60" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Label Margin="5" Grid.Column="0" Grid.Row="0">List of Student
                    :</Label>
                <Label Margin="5" Grid.Column="0" Grid.Row="1">Address:</Label>
                <Label Margin="5" Grid.Column="0" Grid.Row="2">Comment:</Label>
                <RichTextBox Margin="5" Grid.Column="1" Grid.Row="0" MinWidth="100" />
                <RichTextBox Margin="5" Grid.Column="1" Grid.Row="1" MinWidth="100" />
                <RichTextBox Margin="5" Grid.Column="1" Grid.Row="2" MinWidth="100" />
            </Grid>
        </ScrollViewer>
    </Grid>
</Window>

No comments:

Post a Comment