包装面板上的WPF滚动条变灰

时间:2018-07-12 20:41:03

标签: c# wpf scrollbar

我已经阅读了许多与此相关的主题,但是找不到解决方案。在WPF中,我试图在包装板上放置垂直滚动条。我正在动态构建包装面板,它具有标签和文本框。这是包裹在滚动查看器中的包裹面板...

<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>

这是动态构建每一行的C#代码...

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 });
                        }

我确实在屏幕右侧看到一个垂直滚动条,但是即使我超出了我的空间,该滚动条也始终显示为灰色。关于如何使滚动打开/不显示灰色的任何想法? / p>

这是我的带有父边框容器的包装面板...

 <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>

1 个答案:

答案 0 :(得分:1)

如果要垂直实现环绕面板的方向为“水平”,请将方向更改为“垂直”。那就在这里工作正常。