Search code examples
wpflistboxscrollbar

WPF Scrollbar missing - There is no scrollbar shown in the inner listbox inside another list box


In my example, I have a list box (CommentsList). Every item in the list has another inner list ( repliesList). When I have have some commens the vertical scroll bar is shown but when I have a comment with a list or replays the Vertical Scroll bar is not shown. Here you have the xaml design, could you please tell me where is the error?

CommentsPanel.xaml:

 <DockPanel LastChildFill="True" HorizontalAlignment="Stretch" VerticalAlignment="Top">
            <TextBlock DockPanel.Dock="Bottom" TextWrapping="Wrap" Visibility="{Binding HasComments, Converter={StaticResource reversedBooleanToVisibilityConverter}}" Text="There are no comments on this row." x:Name="NoCommentsLabel"/>
            <TextBlock DockPanel.Dock="Bottom" TextWrapping="Wrap"  Text="Use Previous and Next to navigate throught all comments." x:Name="NoCommentsOpenDiagramsLabel">
                <TextBlock.Visibility>
                    <MultiBinding Converter="{StaticResource multiBooleanToVisibilityConverter}">
                        <Binding Path="HasComments"/>
                        <Binding Path="CommentsOnOpenDiagrams" />
                    </MultiBinding>
                </TextBlock.Visibility>
            </TextBlock>
            <ListBox DockPanel.Dock="Bottom" x:Name="CommentsList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=CommentsListItems.View}" 
                        HorizontalContentAlignment="Stretch" BorderThickness="0" Background="Transparent"  SelectionMode="Single" SelectionChanged="CommentsList_OnSelectionChanged"
                        Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <wpfControlLibrary:CommentThread Margin="2,2,5,5" IsSelected="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}, UpdateSourceTrigger=PropertyChanged}"
                                Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}">
                        </wpfControlLibrary:CommentThread>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>

wpfControlLibrary:CommentThread :

<Border x:Name="borderMain" BorderBrush="Transparent" BorderThickness="1" Background="#00000000" Padding="3">
        <Grid x:Name="commentGrid">
            <Grid x:Name="threadGrid" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*"/>
                    <RowDefinition  Height="Auto" />
                </Grid.RowDefinitions>
              <ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding Path=CommentModel}">
                <ContentPresenter.Style>
                  <Style TargetType="ContentPresenter">
                   <Setter Property="ContentTemplate" Value="{StaticResource NoLyncTemplate}" />
                  </Style>
                </ContentPresenter.Style>
              </ContentPresenter>
                **<ListBox Margin="50, 0, 0 0" Grid.Row="1" x:Name="repliesList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemContainerStyle="{StaticResource ContainerStyle}" HorizontalContentAlignment="Stretch" SelectionChanged="RepliesList_OnSelectionChanged" BorderThickness="0" Background="Transparent"  SelectionMode="Single" Grid.Column="0" Grid.ColumnSpan="2" Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}" ItemsSource="{Binding Path=CommentRepliesListItems.View}"**
                     >
                <Grid Grid.Row="3" Margin="50,0,0,0" >
                <TextBlock x:Name="watermark_TextBlock" Text="Reply..." Foreground="{StaticResource brushWatermarkForeground}" Background="{StaticResource brushWatermarkBackground}"
Width="{Binding ActualWidth, ElementName=threadGrid, Mode=OneWay}" HorizontalAlignment="Left" MouseLeftButtonUp="Watermark_OnMouseLeftButtonUp" KeyUp="Watermark_KeyUp">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Style.Triggers>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsMouseOver" Value="True"></Condition>
                                        <Condition Property="Visibility" Value="Visible"></Condition>
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Cursor" Value="IBeam"></Setter>
                                </MultiTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
                <TextBox x:Name="replyBox" Text="" Visibility="Collapsed"                          HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalAlignment="Top" Height="40"
                         VerticalScrollBarVisibility="Auto" LostFocus="CommentEdit_OnLostFocus"
                         KeyUp="ReplyBox_OnKeyUp"
                    />
            </Grid>
            </Grid>
        </Grid>
    </Border>

Solution

  • The solution is use physical scrolling instead of logical scrolling in the listbox: ScrollViewer.CanContentScroll="False"