Jordan Brooker
Jordan Brooker

Reputation: 1201

Display User Control in ScrollViewer

I have a scroll viewer that I want to display all of my user controls. I have two types of user controls which are education and work. They are just text boxes and a button. I dynamically create various numbers of each and add them to a list of type usercontrol. However I cannot get all of the user controls to display!

Scroll Viewer xaml

<ScrollViewer x:Name="myScrollViewer" HorizontalAlignment="Left" Height="518" Margin="128,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="1123" FontSize="22"/>

Code behind

List<UserControl> info = new List<UserControl>();
EducationControl educationControl = new EducationControl(school._school, school._degree, school._fieldOfStudy, school._educationStartDate, school._educationEndDate);
info.Add(educationControl);
WorkControl workControl = new WorkControl(work._employer, work._jobTitle, work._jobStartDate, work._jobEndDate);
info.Add(workControl);
myScrollViewer.Content = info;

When I set the content of the scrollviewer to info, it just displays a string like: System.Collections.Generic.list'1[Windows.UI.Xaml.Controls.UserControl]

However the I can get an individual usercontrol to display properly when I do:

myScrollViewer.Content = info.ElementAt(0);

How can I display all of the user controls in the scroll viewer?

Upvotes: 1

Views: 1254

Answers (1)

Dan J
Dan J

Reputation: 16708

The ScrollViewer's content must be a list-style control, such as a ListBox. By itself, the ScrollViewer doesn't know how to render a List<UserControl>, so it just prints the type name.

It looks like you probably want items to become the ItemsSource of a ListBox or similar control.

Upvotes: 1

Related Questions