0

I am currently working on WPF project and trying to make a Data Grid List View inside Scroll View as scrollable. But it is not working Please suggest any solutions for this

        <ScrollViewer  ScrollViewer.VerticalScrollBarVisibility="Visible" CanContentScroll="True" Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}"  >
                        <DataGrid x:Name="listView"   ItemsSource="{Binding PlayingList,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" HeadersVisibility="None"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"  ScrollViewer.VerticalScrollBarVisibility="Disabled"   HorizontalAlignment="Center"  GridLinesVisibility="None" IsReadOnly="True"
                  SelectedItem="{Binding SelecteddSongList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"
                   AlternationCount="2"     VirtualizingStackPanel.IsVirtualizing="True"  IsHitTestVisible="True"  SelectionMode="Single" PreviewMouseLeftButtonDown="listView_PreviewMouseLeftButtonDown"
                      PreviewMouseRightButtonDown="listView_PreviewMouseRightButtonDown"   SelectionChanged="listView_SelectionChanged"  >
                        <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow">
                                <Setter Property="IsEnabled" Value="True"/>                                                                  
                                <Setter Property="FontSize" Value="14"/>
                                <Setter Property="FontFamily" Value="Cartina"/>
                                <Style.Triggers>                                    
                                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                                        <Setter Property="Background" Value="#1a0000"></Setter>
                                        <Setter Property="Foreground" Value="#FFC934"></Setter>
                                    </Trigger>
                                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                        <Setter Property="Background" Value="#330000"></Setter>
                                        <Setter Property="Foreground" Value="#FFC934"></Setter>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="#fff8e6" />
                                        <Setter Property="Foreground" Value="#330000"></Setter>
                                        <Setter Property="FontSize" Value="16"></Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>
                                               </DataGrid>
                  </ScrollViewer>

My code behind code is as under

private void listView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (e.RightButton != MouseButtonState.Pressed)
            base.OnPreviewMouseRightButtonDown(e);
    }
Next Olive
  • 39
  • 2
  • 6

1 Answers1

0

This question may help you. DataGrid should not need a ScrollViewer to enable scrolling. Instead of creating the ScrollViewer, set the VerticalScrollBarVisibility property on the DataGrid.

Andrew H
  • 875
  • 5
  • 20