【问题标题】:WPF ScrollViewer Not Scrolling VerticallyWPF ScrollViewer 不垂直滚动
【发布时间】:2012-05-03 01:03:43
【问题描述】:

我有一个包含在用户控件中的列表框。当设置为水平方向时,它会按预期滚动,但是当我将其更改为垂直时,当我按下键盘上的向下键时,所选项目会继续向下更改列表,但没有滚动,因此您无法再看到所选项目。它基本上只是从屏幕底部消失。

页面布局有一个网格,它周围有一个不会离开屏幕的边框。 在这个网格中有一个 ContentControl

<Grid Grid.Column="1" Margin="0,30,30,30" Opacity=".7">
        <Border BorderBrush="#FFFFFFFF" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" >
            <Border.Effect>
                <BlurEffect KernelType="Gaussian" Radius="4"/>
            </Border.Effect>
        </Border>
        <Grid Background="Black">
            <ContentControl Content="{Binding SelectedSettingViewModel}" Focusable="False" />
        </Grid>
    </Grid>

在这个内容控件中是一个用户控件。 用户控件内部是我遇到问题的列表框。

<UserControl>
<Grid >
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Controls:KNListBox Grid.Row="4" x:Name="SettingsListBox" KeyboardNavigation.DirectionalNavigation="Continue" ItemsSource="{Binding AutoCompleteDirectories}"
                            Style="{DynamicResource SettingsListBox}" SelectedItem="{Binding SelectedAutoCompleteDirectory, Mode=TwoWay}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"></StackPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </Controls:KNListBox>
</Grid>
</UserControl>

我尝试过更改网格高度并删除 ListBox 的样式,但没有任何乐趣。谁能看出我哪里出错了?

【问题讨论】:

    标签: asp.net wpf


    【解决方案1】:

    通过将包含列表框的行定义从 Auto 更改为 * 来解决此问题。自动将行扩展到列表框的大小,因此它会从屏幕上消失并且永远不会滚动。

    <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      相关资源
      最近更新 更多