Sss
Sss

Reputation: 1529

How to aassign list values to scrollbar in c#

I am working on silverlight and i have to code in c# only not in xaml. I have a list and a ScrollViewer and i try to assign the list in scrollviewer vertically like this:

List<string> lines = new List<string>();  
 ScrollViewer scrollViewer = new ScrollViewer();       
        foreach (var item in param.Component.Attributes.Items)
        {
            lines.Add(item);               
            outputBlock.Text = displayMembers(lines);
            scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            scrollViewer.Content = lines;                              
        }
        Grid.SetColumn(scrollViewer, 1);
        Grid.SetRow(scrollViewer, 2);
        childGrid.Children.Add(scrollViewer);

Actually the "lines" (List) in my code consists of the data as you can see in the list below (the stings of 1 000 000 and 3 000 000 and 5 000 000 and 10 000 000) but when i see the GUI obtained it shows the string not the number strings that i added in my "lines". The GUI is like this:

enter image description here

and on debugging "Content" (in line scrollViewer.Content = lines;) shows this :

enter image description here

another problem is User here selected 10 000 000 from the list and that is displayed in textblock. How to do that ?

Please note that i am using silverlight and have to code in c#. Thanks for the help.

Upvotes: 0

Views: 99

Answers (1)

Sss
Sss

Reputation: 1529

I created a ListBox instead of List and it worked.

see the code below :

            ListBox lines = new ListBox(); 
            ScrollViewer scrollViewer = new ScrollViewer();            
            scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            foreach (var item in param.Component.Attributes.Items)
            {
                lines.Items.Add(item);    
                scrollViewer.Content = lines;                            
            }                

        Grid.SetColumn(scrollViewer, 1);
        Grid.SetRow(scrollViewer, LoopCount);
        childGrid.Children.Add(scrollViewer);

Upvotes: 1

Related Questions