Updated on Kisan Patel
Problem:
How to create a scrollable WPF usercontrol?
For an application that I am working on I want to create a custom control that has several textbox on it, If there are too many textbox I need it to scroll.
Solution:
You would normally use a ScrollViewer
to achieve this. For example:
<UserControl x:Class="WpfApplication2.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="300"> <ScrollViewer> </ScrollViewer> </UserControl>
Will display a vertical scrollbar automatically when required.
You can change the behaviour by specifying VerticalScrollbarVisibility
like this
<ScrollViewer VerticalScrollBarVisibility="Auto"> <ScrollViewer VerticalScrollBarVisibility="Visible"> <ScrollViewer VerticalScrollBarVisibility="Hidden"> <ScrollViewer VerticalScrollBarVisibility="Disabled">
There is of course a HorizontalScrollBarVisibility
property as well.