1

I want a stackpanel that will scroll after a min window size is hit but expand when the window grows horizontally.

I can make the grow functionality work if I drop the stack panel into a window and anchor it but then I can't scroll.

If I use a scrollViewer then I get the scroll bars but the stack panel never grows horizontally.

Basically I need an equivalent to WinForms AutoSizeMode GrowOnly

<Window
         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" 
         xmlns:views="clr-namespace:Miner.Responder.Explorer.IncidentReview.Views"
         x:Class="Miner.Responder.Explorer.IncidentReview.Views.IncidentReviewForm"
         mc:Ignorable="d" Height="1069.2" Width="1096">
<ScrollViewer Margin="0,0,2,1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <StackPanel Height="1018" Width="1080" RenderTransformOrigin="0.5,0.5">
        <StackPanel.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform AngleX="0.057"/>
                <RotateTransform/>
                <TranslateTransform X="0.499"/>
            </TransformGroup>
        </StackPanel.RenderTransform>
        <views:IncidentReviewView x:Name="ucIncident" Height="532" Margin="38,0" Width="Auto"/>
        <views:TimeEditor x:Name="ucTimes" Height="166" Margin="38,0" Width="Auto"/>
        <views:HistoryTables x:Name="ucHistory" Height="287"/>
        <Grid Height="30">
            <Button x:Name="BtnOk" Content="OK" Margin="0,0,6,2" RenderTransformOrigin="-0.36,0.558" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" />
            <Button x:Name="BtnCancel" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,166,2" VerticalAlignment="Bottom" Width="76" IsCancel="True" IsDefault="True"/>
            <Button x:Name="BtnSave" Content="Save" HorizontalAlignment="Right" Margin="0,0,86,2" VerticalAlignment="Bottom" Width="75"/>
        </Grid>
    </StackPanel>
</ScrollViewer>

Jakobitz
  • 71
  • 1
  • 5
  • First, you need to post your code before this is a complete question – DotNetRussell Jun 14 '19 at 19:24
  • You need to fix the height of your stackpanel otherwise it will grow forever inside a scrollviewer. https://stackoverflow.com/questions/802821/how-can-i-get-scrollviewer-to-work-inside-a-stackpanel – Spell Jun 14 '19 at 19:27
  • I think it is fixed. Height = 1018 – Jakobitz Jun 14 '19 at 19:31
  • I would use a DockPanel instead of a StackPanel, I found it to be alot easier to control. This answer has a similar problem and went with a DockPanel https://stackoverflow.com/questions/569095/how-to-get-stackpanels-children-to-fill-maximum-space-downward – Max Young Jun 14 '19 at 19:45
  • They seem more concerned about the vertical growth. I think my problem is that I can't anchor the stack panel to the scrollviewer so the stack panel does not grow horizontally with the scrollviewer. – Jakobitz Jun 14 '19 at 19:56
  • Few questions here, 1 do you need all those Margins? That looks like a botched up UI. 2 RenderTransform is that really necessary? 3 Naming controls?! (unless you use them in Bindings or Triggers there is no need for that), whole thing reeks of `WinForms` BEWARE IF YOU THINK WPF IS THE SAME AS WINFORMS, **IT IS NOT!!!** That grid at the bottom needs Column definitions instead of fixed position buttons with names remove the Height attribute and watch it work without it. – XAMlMAX Jun 14 '19 at 22:41
  • While I realize I am new to WPF I don't see how your comment helps answer my question. The designer has added a few things to my xaml and I am not concerned with that right now. Can anyone explain why I can't anchor to a scrollview or give me another control that allows scrolling? – Jakobitz Jun 17 '19 at 14:21

0 Answers0