[英]WPF scroll bar on wrap panel grayed out
我已经阅读了很多相关主题,但找不到解决方案。 在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>
如果要垂直实现包装面板的方向为水平,请将方向更改为“垂直”。 那时工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.