gpt4 book ai didi

c# - 环绕面板上的 WPF 滚动条变灰

转载 作者:行者123 更新时间:2023-11-30 17:29:20 24 4
gpt4 key购买 nike

我已经阅读了许多关于此的相关主题,但找不到解决方案。在 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 });
}

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

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

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

最佳答案

为什么wrap panel的orientation是Horizo​​ntal的,如果要垂直实现,把orientation改成Vertical。它在这里工作正常。

关于c# - 环绕面板上的 WPF 滚动条变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51314113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com