scrollviewer

WPF: How to make canvas auto-resize?

隐身守侯 提交于 2019-11-26 03:56:33
问题 I would like my Canvas to automatically resize to the size of its items, so that the ScrollViewer scroll bars have the correct range. Can this be done in XAML? <ScrollViewer HorizontalScrollBarVisibility=\"Auto\" x:Name=\"_scrollViewer\"> <Grid x:Name =\"_canvasGrid\" Background=\"Yellow\"> <Canvas x:Name=\"_canvas\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Background=\"Green\"></Canvas> <Line IsHitTestVisible=\"False\" .../> </Grid> </ScrollViewer> In the above code the canvas

How can I get ScrollViewer to work inside a StackPanel?

此生再无相见时 提交于 2019-11-26 03:42:00
问题 In the following WPF XAML the ScrollViewer does not work (it displays a scroll bar but you cannot scroll and the contents go off the window to the bottom). I can change the outer StackPanel to a Grid and it will work. However, in my application from which I reproduced the following code, I need to have an outer StackPanel. What do I have to do to the StackPanel to make the ScrollViewer show a usable scrollbar? e.g. VerticalAlignment=\"Stretch\" Height=\"Auto\" don\'t work. <StackPanel>