ScrollViewer Actualwidth

Jun 16, 2009 at 4:18 PM

I am having trouble getting a ScrollViewer width to behave as I expect. The height is working as desired.

The ScrollViewer is the top level item in a control that has a stack panel with a bunch of expanders in it. Some of the expanders contain a datagrid. When the width of the datagrid exceeds the width of the window I expect the scrollbar to appear so I can scroll to the right. It does not appear. When I examine the Actualwidth value it is set to  5672.6166666667 which is very wide. If I run the application on a machine with 4 22" monitors I can get to the far right of the datagrid and see the vertical scroll bar.

This control gets placed in a TabItem which is in a TabControl which is in another StackPanel.

How can I get the ScrollViewer Actualwidth to be set correctly. I have removed all the references to width I could find so I don't think I am setting it anywhere.



Jun 16, 2009 at 9:47 PM

Hi TomGroszko,

A StackPanel will stretch itself to the width of its contents and hence you see the ScrollViewer ActualWidth as something big. If you use a Grid instead it will restrict itself. Hope this works.



Jun 17, 2009 at 2:06 PM

I started with a grid and had several problems. At your suggestion I went back and tried it again and it is working as I would like now.

Thanks for the explaination.