Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF scroll bar on wrap panel grayed out

Tags:

c#

wpf

scrollbar

I have read numerous related topics on this but can't find a solution. In WPF I am trying to place a vertical scroll bar on a wrap panel. I am dynamically building the wrap panel and it has labels and textboxes. Here is my wrap panel wrapped in a scroll viewer...

<ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True" IsEnabled="True" AllowDrop="True">
                        <WrapPanel Orientation="Horizontal" Name="wpAddAttribute" Width="1129" IsEnabled="True" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible"></WrapPanel>
                    </ScrollViewer>

Here is the C# code to dynamically build each row...

private void AddAttribute(object sender, RoutedEventArgs e)
        {
            wpAddAttribute.Children.Add(new Label { Content = "Attribute Name", Name = "lbNewTestAttributeNameLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeName", Width = 75 });
            wpAddAttribute.Children.Add(new Label { Content = "Attribute Value", Name = "lbNewTestAttributeValueLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeValue", Width = 55 });
            wpAddAttribute.Children.Add(new Label { Content = "Attribute Units", Name = "lbNewTestAttributeUnitsLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeUnits", Width = 55 });

            wpAddAttribute.Children.Add(new Label { Content = "Attribute Minimum Value", Name = "lbNewTestAttributeMinValueLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeMinValue", Width = 55 });
            wpAddAttribute.Children.Add(new Label { Content = "Attribute Maximum Value", Name = "lbNewTestAttributeMaxValueLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeMaxValue", Width = 55 });

            wpAddAttribute.Children.Add(new Label { Content = "Stepping Minimum Value", Name = "lbNewTestSteppingMinValueLabel" });
            wpAddAttribute.Children.Add(new TextBox { Height = 26, Name = "tbNewTestAttributeMinValue", Width = 55 });
                        }

I do see a vertical scroll bar on the right side of the screen but it is always grayed out, even when I exceed the space I'm in. Any ideas of how to get the scrolling on/not grayed out?

Here is my wrap panel with the parent border container...

 <Border Name="bdAddTestArea" Visibility="Collapsed" Background="DeepSkyBlue" BorderThickness="2" BorderBrush="Black" CornerRadius="10"  Margin="10" Width="1130" Height="330" ScrollViewer.CanContentScroll="True">
            <StackPanel ScrollViewer.CanContentScroll="True">
                <StackPanel Orientation="Vertical" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <TextBlock Margin="4 0 0 0">Add a Test</TextBlock>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="New Test Name:"></Label>
                        <TextBox Name="tbNewTestName" Width="75"></TextBox>
                        <Label Content="Test Estimate (in seconds):"></Label>
                        <TextBox Name="tbTestEstimate" Width="75"></TextBox>
                    </StackPanel>
                    <ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True" IsEnabled="True" AllowDrop="True">
                        <WrapPanel Orientation="Horizontal" Name="wpAddAttribute" Width="1129" IsEnabled="True" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible"></WrapPanel>
                    </ScrollViewer>
                </StackPanel>

                <StackPanel Visibility="Visible" Orientation="Horizontal" >
                </StackPanel>
                <Button Content="Add an Attribute" Click="AddAttribute" Width="96" Margin="5 5 0 0" HorizontalAlignment="Left"></Button>
                <Button Content="Save Test" Click="SaveTest" Height="20" HorizontalAlignment="Left" Margin="5 5 0 0"></Button>
                <Button Content="Return To Test Selection" Click="ReturnToSelectionPanel" Height="20" HorizontalAlignment="Left" Margin="5 5 0 0"></Button>

            </StackPanel>
        </Border>
like image 734
ScottS Avatar asked Dec 06 '25 05:12

ScottS


1 Answers

Why the orientation of wrap panel is Horizontal if you want to implement it vertically, change orientation to Vertical. It is working fine here then.

like image 73
Gaurav Jalan Avatar answered Dec 09 '25 04:12

Gaurav Jalan